Another DLOOKUP question

G

Guest

Hello all,

I thought I figured out the DLOOKUP syntax, but no..... I have this bit of
code, that I think should be returning the same values in the first two
message boxes. It seems the DLOOKUP is pulling back the values in the first
record, regardless of the criteria.
I've tried using Me.StudentID in the criteria as well as what is listed below.
Any assistance is very much appreciated.
'** start of partial code **
First_Name = DLookup("[Student First Name]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Last_Name = DLookup("[Student Last Name]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Temp_ID = DLookup("[StudentID]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

MsgBox Forms![frm Class Lists -Tabular].StudentID & " Form ID"
'returns the number 38 correctly

MsgBox Temp_ID & " Lookup ID"
'returns the number 1

MsgBox First_Name
'returns the first name of student id 1

MsgBox Last_Name
'returns the last name of student id 1
'** end of partial code **

Thank you
 
G

Guest

Try this
' If student id is number type
First_Name = DLookup("[Student First Name]", "[Student]", "[StudentID] = " &
Forms![frm Class Lists -Tabular].StudentID)

' If student id is text type
First_Name = DLookup("[Student First Name]", "[Student]", "[StudentID] = '"
& Forms![frm Class Lists -Tabular].StudentID & "'")

==========================================
Or you combine all the dlookup's to one dlookup
dlookup("[Student First Name] & ' ' & [Student Last
Name]","[Student]","[StudentID]=" & Forms![frm Class Lists
-Tabular].StudentID )
============================================
And, why do you need this
Temp_ID = DLookup("[StudentID]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Why do you need to return a value that you already have
=============================================
 
G

Guest

Ofer,
Works perfectly.

THANK YOU.

The studentID lookup was to figure out what dlookup was doing.

Ofer said:
Try this
' If student id is number type
First_Name = DLookup("[Student First Name]", "[Student]", "[StudentID] = " &
Forms![frm Class Lists -Tabular].StudentID)

' If student id is text type
First_Name = DLookup("[Student First Name]", "[Student]", "[StudentID] = '"
& Forms![frm Class Lists -Tabular].StudentID & "'")

==========================================
Or you combine all the dlookup's to one dlookup
dlookup("[Student First Name] & ' ' & [Student Last
Name]","[Student]","[StudentID]=" & Forms![frm Class Lists
-Tabular].StudentID )
============================================
And, why do you need this
Temp_ID = DLookup("[StudentID]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Why do you need to return a value that you already have
=============================================
--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



David said:
Hello all,

I thought I figured out the DLOOKUP syntax, but no..... I have this bit of
code, that I think should be returning the same values in the first two
message boxes. It seems the DLOOKUP is pulling back the values in the first
record, regardless of the criteria.
I've tried using Me.StudentID in the criteria as well as what is listed below.
Any assistance is very much appreciated.
'** start of partial code **
First_Name = DLookup("[Student First Name]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Last_Name = DLookup("[Student Last Name]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

Temp_ID = DLookup("[StudentID]", "[Student]", _
[StudentID] = Forms![frm Class Lists -Tabular].StudentID)

MsgBox Forms![frm Class Lists -Tabular].StudentID & " Form ID"
'returns the number 38 correctly

MsgBox Temp_ID & " Lookup ID"
'returns the number 1

MsgBox First_Name
'returns the first name of student id 1

MsgBox Last_Name
'returns the last name of student id 1
'** end of partial code **

Thank you
 

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