DLookup & Set

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

DLookup & Set

Post by burrina »

Trying to lookup a value and set or append to table that has no value in it. txtComputerName has the name of the computer in it
pcID is a text field. Be default on a new pc it will have no value or computer name.
If IsNull(DLookup("[pcID]", "tblUserSecurityAutoLogin")) Then

DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblUserSecurityAutoLogin SET tblUserSecurityAutoLogin.pcID'" = "[txtComputerName].Value"
DoCmd.SetWarnings True
End If

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup & Set

Post by burrina »

Update: Don't know why this would not work but I decided on just using a hidden form and comparing to that. Still, I would like to know what I was doing wrong?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DLookup & Set

Post by HansV »

Does the table contain a record with an empty pcID field, or does it not have any records yet?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup & Set

Post by burrina »

Empty, no records

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DLookup & Set

Post by HansV »

In that case you need INSERT instead of UPDATE:

Code: Select all

DoCmd.RunSQL "INSERT INTO tblUserSecurityAutoLogin (pcID) VALUES ('" & txtComputerName &"')"
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup & Set

Post by burrina »

Thanks once again, Hans. Appreciate the ideas and help.