DlookUp

J

Julia82

Hello,

I have:
Me.User.Value = DLookup("Access", "UserT", "UID= " &Name)

where:
User = Text Box
Access = Field 3 from Table "UserT" (text)
UID = Field 1 = Autonumber (number)
Name = Field 2 from Table "UserT" (text)

I Want:

To lookup for the Access of the Name in the UserT Table.
I want to veryfi What access has the username in the same table by the id of
the name in the same table. Hope this makes sense.

I have two text boxes. When there is text in that textbox, I want the text
to be verifyed in the table UserT and to read from Access field and display
value.

What do I do wrong? Thanks!
 
J

Jeanette Cunningham

I suggest you use a combo instead of a textbox.
The combo's row source would be a query with UID and Name for the 2 columns.
After user chooses their name from the combo, you can do the DLookup.

Me.User = DLookup("Access", "UserT", "UID= " & [NameOfCombo])

The above code will show the value of "Access" in the second textbox.

I also recommend using Nz in case the dlookup can't find a matching value.

Me.User = Nz(DLookup("Access", "UserT", "UID= " & [NameOfCombo]),"no
access")



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Julia82

Thanks for your reply Janette,

But if I don't want to use a combo instead of textbox, there is a way to get
this done?

Thank You!

Jeanette Cunningham said:
I suggest you use a combo instead of a textbox.
The combo's row source would be a query with UID and Name for the 2 columns.
After user chooses their name from the combo, you can do the DLookup.

Me.User = DLookup("Access", "UserT", "UID= " & [NameOfCombo])

The above code will show the value of "Access" in the second textbox.

I also recommend using Nz in case the dlookup can't find a matching value.

Me.User = Nz(DLookup("Access", "UserT", "UID= " & [NameOfCombo]),"no
access")



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

Julia82 said:
Hello,

I have:
Me.User.Value = DLookup("Access", "UserT", "UID= " &Name)

where:
User = Text Box
Access = Field 3 from Table "UserT" (text)
UID = Field 1 = Autonumber (number)
Name = Field 2 from Table "UserT" (text)

I Want:

To lookup for the Access of the Name in the UserT Table.
I want to veryfi What access has the username in the same table by the id
of
the name in the same table. Hope this makes sense.

I have two text boxes. When there is text in that textbox, I want the text
to be verifyed in the table UserT and to read from Access field and
display
value.

What do I do wrong? Thanks!


.
 
J

Julia82

Sorry,

I ment if I want to use a textbox instead of combo like you said, this can
be done?
 
J

Jeanette Cunningham

Do you want the user to type their name into the textbox?
If Yes, then change the DLookup like this

Me.User = Nz(DLookup("Access", "UserT", "[NameOfNameField]= """ &
[NameOfNameControl] & """"),"no
access")

Note: replace field and control names to match those on your form and table.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Julia82

Thanks for your time.

I had to find out that there are 3 types of expressions. One for the date,
one if it's a number and another one if it's a text, how I had.

Now works perfectly.

Jeanette Cunningham said:
Do you want the user to type their name into the textbox?
If Yes, then change the DLookup like this

Me.User = Nz(DLookup("Access", "UserT", "[NameOfNameField]= """ &
[NameOfNameControl] & """"),"no
access")

Note: replace field and control names to match those on your form and table.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


Julia82 said:
Sorry,

I ment if I want to use a textbox instead of combo like you said, this can
be done?


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top