using dlookup

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi,

I have a value within a textbox returning "lanID" with some VBA behind this..

I would like to lookup this value in the textbox (textbox is called userID) and return "where "lanID" = "User Name" in the "staff" table..

hope that makes sense

Many thanks for the help
 
Hi - please see code below

The code builder doesn't like [ ] around the UserList (domain) (text goes red in the code builder)

The code is within still as I'm unsure how to reference it when in a standard module. In this project I think it should be ok to keep it here?

also it errors with the & '") after svLanID.

At the moment, the code doesn't return an error, it just leaves a blank text box

much appreciated


Private Sub tb_fullname_load()
Dim svUserName As String, svLanID As String
svLanID = fOSUserName 'can't remember if you need the () at the end
svUserName = DLookup("[Analyst Name]", "UserList", "[Lan ID]='" & svLanID)
Me.tbFullName = svUserName
End Sub
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Now resolved..

i've used the =fOSusername on a text box.. Hidden it.. and then done a dlookup in the expression builder.

Thanks for your advice and guidance on the way!
 
Upvote 0
You're welcome - glad you got it solved. I'm betting you did not check out DLookup as suggested, otherwise I think you would have caught my mistake! I forgot the closing quote. & svLanID) should have been & svLanID & ') ". This could cause anyone to believe the brackets were the problem as the errors are often flagged as close to the real problem as possible, but it's not always pinpoint accuracy. If they are around a domain or field name, should not be a problem. You probably rectified that by using the expression builder. My excuse is that I was tired. What's yours? ;)

The code is within still as I'm unsure how to reference it when in a standard module. In this project I think it should be ok to keep it here?
You call it the same way I did (svLanID = fOSUserName). The difference is that being in a standard module exposes it to the entire project. You should consider making it work this way. Down the road, you might find this useful in several ways in this project. For example, you can pass the user name to a query if you want to capture who updates the database, retrieve records related to the user, etc. If you do not, I'd comment out the code to avoid the possibility of getting the error "Ambiguous name detected" but keep it for future reference.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top