Vis basic coding help??

kanga202

New member
Local time
Today, 19:06
Joined
Oct 5, 2005
Messages
8
Ok I’m coding a form, heres what I have done so far

Me.FN LN =DLookUp("[First Name] & ' ' & [Last Name]","tblStaffID", "Staff ID=" & Me.Staff ID")

I have a txt box to imput the Staff ID number in to and I want it to return the first and last name in to another txt box

Am I close??? What am I doing wrong here??

The table this is coming off is just three fields “Staff ID” “Last Name” “First Name”

Can anyone help??
 
At first glance, I would standardize the name of your text boxes, and NEVER use spaces in the name, for example: instead of FN LN use something like txtName.

As for your DLookup, get rid of that last quotation mark and see what happens.

P.S. I don't use spaces when naming controls, fields, tables, forms, etc etc etc... if you want to indicate a space, I suggest using an underscore. You won't regret this small effort in the long run.
 
Thanks heaps for that, yep i got rid of the spaces and the last quotation mark, but ill go though and standisise the names thanks for that

but its still not working... well @ least i'm getting the first name and last name to come up but it doset not seem to have anything to do with the staff id i have entered

gah have to go home for the day, (so sorry bout the spelling...dyslexic)

again thanks so much for the advise
 
Out of curiosity, under what event are you placing this code?
 
Try:

Me.FN LN =DLookUp("[First Name] & ' ' & [Last Name]","tblStaffID", "Staff ID='" & Me.Staff ID & "'")

From my code repository:

Getting a value from a table: DLookup()
Sooner or later, you will need to retrieve a value stored in a table. If you regularly make write invoices to companies, you will have a Company table that contains all the company's details including a CompanyID field, and a Contract table that stores just the CompanyID to look up those details. Sometimes you can base your form or report on a query that contains all the additional tables. Other times, DLookup() will be a life-saver.
DLookup() expects you to give it three things inside the brackets. Think of them as:
Look up the _____ field, from the _____ table, where the record is _____
Each of these must go in quotes, separated by commas.
This is probably easiest to follow with some examples:
1. you have a CompanyID such as 874, and want to print the company name on a report;
2. you have Category such as "C", and need to show what this category means.
3. you have StudentID such as "JoneFr", and need the student’s full name on a form.
Example 1:
Look up the CompanyName field from table Company, where CompanyID = 874. This translates to:
=DLookup("CompanyName", "Company", "CompanyID = 874")
You don't want Company 874 printed for every record! Use an ampersand (&) to concatenate the current value in the CompanyID field of your report to the "Company = " criteria:
=DLookup("CompanyName", "Company", "CompanyID = " & [CompanyID])
Example 2:
The example above is correct if CompanyID is a number. But if the field is text, Access expects quote marks around it. In our second example, we look up the CategoryName field in table Cat, where Category = 'C'. This means the DLookup becomes:
=DLookup("CategoryName", "Cat", "Category = 'C'")
Single quotes within the double quotes is the easiest way to do quotes within quotes. But again, we don't want Category 'C' for all records: we need the current value from our Category field patched into the quote. To do this, we close the quotation after the first single quotemark, add the contents of Category, and then add the trailing single quotemark. This becomes:
=DLookup("CategoryName", "Cat", "Category = '" & [Category] & "'")
Example 3:
In our third example, we need the full name from a Student table. But the student table has the name split into FirstName and Surname fields, so we need to refer to them both and add a space between. To show this information on your form, add a textbox with ControlSource:
=DLookup("[FirstName] & ' ' & [Surname]", "Student", "StudentID = '" & [StudentID] & "'")

Dave
 
Hay Dave thanks so much

What is it with the combo box fanatics on these forums ;)

I can’t use combo boxes... every employ has to enter there name individually...

but thanks :)

@ ssteinke, err event???? i'm new here... actualy i'm just kinda fingering this out as i go so lol...
 
Last edited:
Nah doesn’t work… putting any of the staff IDs in just brings up the first and last name for staff number 23… which is nether @ the beginning or end of the table(if that makes a difference) better than nothing though, anyway ill have a look through the other info in your post and see if something occurs to me

And thanks again for your help Dave :)

Shane
 
ssteinke Out of curiosity, under what event are you placing this code?

yeah... i was wondering whats the best thing to put it under??
 
Try placing the code in the 'AfterUpdate' event of the textbox you called Staff ID
 

Users who are viewing this thread

Back
Top Bottom