PC Review


Reply
Thread Tools Rate Thread

Change value in a table using VBA

 
 
hollyylloh
Guest
Posts: n/a
 
      5th Feb 2009
I am using a Dlookup function to return a record from a table and then I
would like to set the value of a field in that record. I have:

Dim acctype as variant

acctype = Dlookup("[AccType]", "tblPermit", "[User] = Forms!frmSignin!user
and [Password] = Forms!frmSignin!password")

If acctype = "Writer" then
docmd.OpenForm "frmMain"
Forms!frmMain!cmdCompany.Enabled = True
' need help here to write a value to the table ?? Tables!tblPermit!Loggedin
= True
' for the user referenced in the Dlookup ??

End if

Perhaps me approach is all wrong? Should I be referencing a recordset?
Thanks for your help!
 
Reply With Quote
 
 
 
 
Jim Burke in Novi
Guest
Posts: n/a
 
      5th Feb 2009
One way to do it:

dim SQLText as string

SQLText = "UPDATE tblPermit " & _
"SET LoggedIn = True " & _
"WHERE User = '" & Forms!frmSignin!user & "' AND " & _
" Password = '" & Forms!frmSignin!password & "'"
docmd.runsql SQLText

put that right before you open the main form.

Notice that you need to put quotes around the User and Password values, and
you cannot put the form control names inside the quotes - you need to change
your DLookup to do that as well. And make sure you include blanks where I
have them at the end of lines (e.g. at the end of "UPDATE tblPermit "). Also,
you should include error handling in your routine.

"hollyylloh" wrote:

> I am using a Dlookup function to return a record from a table and then I
> would like to set the value of a field in that record. I have:
>
> Dim acctype as variant
>
> acctype = Dlookup("[AccType]", "tblPermit", "[User] = Forms!frmSignin!user
> and [Password] = Forms!frmSignin!password")
>
> If acctype = "Writer" then
> docmd.OpenForm "frmMain"
> Forms!frmMain!cmdCompany.Enabled = True
> ' need help here to write a value to the table ?? Tables!tblPermit!Loggedin
> = True
> ' for the user referenced in the Dlookup ??
>
> End if
>
> Perhaps me approach is all wrong? Should I be referencing a recordset?
> Thanks for your help!

 
Reply With Quote
 
hollyylloh
Guest
Posts: n/a
 
      6th Feb 2009
Jim, thanks. I did get that to work.
One thing though, is there a way to suppress the dialog which comes up and
asks if I want to confirm the update of one row?

Thanks

"Jim Burke in Novi" wrote:

> One way to do it:
>
> dim SQLText as string
>
> SQLText = "UPDATE tblPermit " & _
> "SET LoggedIn = True " & _
> "WHERE User = '" & Forms!frmSignin!user & "' AND " & _
> " Password = '" & Forms!frmSignin!password & "'"
> docmd.runsql SQLText
>
> put that right before you open the main form.
>
> Notice that you need to put quotes around the User and Password values, and
> you cannot put the form control names inside the quotes - you need to change
> your DLookup to do that as well. And make sure you include blanks where I
> have them at the end of lines (e.g. at the end of "UPDATE tblPermit "). Also,
> you should include error handling in your routine.
>
> "hollyylloh" wrote:
>
> > I am using a Dlookup function to return a record from a table and then I
> > would like to set the value of a field in that record. I have:
> >
> > Dim acctype as variant
> >
> > acctype = Dlookup("[AccType]", "tblPermit", "[User] = Forms!frmSignin!user
> > and [Password] = Forms!frmSignin!password")
> >
> > If acctype = "Writer" then
> > docmd.OpenForm "frmMain"
> > Forms!frmMain!cmdCompany.Enabled = True
> > ' need help here to write a value to the table ?? Tables!tblPermit!Loggedin
> > = True
> > ' for the user referenced in the Dlookup ??
> >
> > End if
> >
> > Perhaps me approach is all wrong? Should I be referencing a recordset?
> > Thanks for your help!

 
Reply With Quote
 
pietlinden@hotmail.com
Guest
Posts: n/a
 
      6th Feb 2009
On Feb 5, 6:00*pm, hollyylloh <hollyyl...@discussions.microsoft.com>
wrote:
> Jim, thanks. I did get that to work.
> One thing though, is there a way to suppress the dialog which comes up and
> asks if I want to confirm the update of one row?
>
> Thanks
>
> "Jim Burke in Novi" wrote:
>
> > One way to do it:

>
> > * *dim SQLText as string

>
> > * *SQLText = "UPDATE tblPermit " & _
> > * * * * * * * * * * "SET LoggedIn = True " & _
> > * * * * * * * * * * "WHERE User = '" & Forms!frmSignin!user & "' AND " & _
> > * * * * * * * * * * " Password *= '" & *Forms!frmSignin!password & "'"
> > * *docmd.runsql SQLText

>


Two ways. Either:

DoCmd.SetWarnings False 'turn them off
DoCmd.RunSQL SQLText
DoCmd.SetWarnings True ' turn them back on

OR

DBEngine(0)(0).Execute SQLText

 
Reply With Quote
 
Tom van Stiphout
Guest
Posts: n/a
 
      6th Feb 2009
On Thu, 5 Feb 2009 16:00:01 -0800, hollyylloh
<(E-Mail Removed)> wrote:

Wrap the code in:
DoCmd.SetWarnings False
'do your thing
DoCmd.SetWarnings True

-Tom.
Microsoft Access MVP


>Jim, thanks. I did get that to work.
>One thing though, is there a way to suppress the dialog which comes up and
>asks if I want to confirm the update of one row?
>
>Thanks
>
>"Jim Burke in Novi" wrote:
>
>> One way to do it:
>>
>> dim SQLText as string
>>
>> SQLText = "UPDATE tblPermit " & _
>> "SET LoggedIn = True " & _
>> "WHERE User = '" & Forms!frmSignin!user & "' AND " & _
>> " Password = '" & Forms!frmSignin!password & "'"
>> docmd.runsql SQLText
>>
>> put that right before you open the main form.
>>
>> Notice that you need to put quotes around the User and Password values, and
>> you cannot put the form control names inside the quotes - you need to change
>> your DLookup to do that as well. And make sure you include blanks where I
>> have them at the end of lines (e.g. at the end of "UPDATE tblPermit "). Also,
>> you should include error handling in your routine.
>>
>> "hollyylloh" wrote:
>>
>> > I am using a Dlookup function to return a record from a table and then I
>> > would like to set the value of a field in that record. I have:
>> >
>> > Dim acctype as variant
>> >
>> > acctype = Dlookup("[AccType]", "tblPermit", "[User] = Forms!frmSignin!user
>> > and [Password] = Forms!frmSignin!password")
>> >
>> > If acctype = "Writer" then
>> > docmd.OpenForm "frmMain"
>> > Forms!frmMain!cmdCompany.Enabled = True
>> > ' need help here to write a value to the table ?? Tables!tblPermit!Loggedin
>> > = True
>> > ' for the user referenced in the Dlookup ??
>> >
>> > End if
>> >
>> > Perhaps me approach is all wrong? Should I be referencing a recordset?
>> > Thanks for your help!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change format in automatic table so it doesn't change back? =?Utf-8?B?VmFsZXJpZQ==?= Microsoft Word Document Management 0 29th Oct 2007 09:41 PM
Change of table name in access where Excel obtains pivot table inf =?Utf-8?B?QW5kcmV3?= Microsoft Excel Programming 3 26th Jul 2007 03:06 AM
Need Interactive Button to link to Table change vice Page Change =?Utf-8?B?QWx3YXlzTWFyaW5l?= Microsoft Frontpage 1 9th Mar 2006 10:22 AM
can I change text field size in output table of make table query? =?Utf-8?B?UE5fU2FtbQ==?= Microsoft Access Queries 2 22nd Dec 2004 05:49 PM
Table cross referenced marked as changed when table contents change. Bruce V. Microsoft Word Document Management 0 5th Nov 2003 08:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 AM.