Dlookup help

G

Guest

i am trying to use the Dlookup function but not getting it working here.
I have on table "Patients" with many fields including these two :
PatientnameId, and PersonalNumber.the Patientnameid is a number field
,wheareas the Personalnumber is a text field.

now , when i enter new record for a patient who already got a previos record
( one record for each Visit) , i just want to type his name in the
PatientNameid field , and to get the PersonalNumber automatically entered .

I have this
Dim varcpr As Variant
varcpr = DLookup("Personalnumber ", "patients", "patientnameid
=[patientNameid] ")
If (Not IsNull(varCpr)) Then Me![Personalnumber ] = varcpr

but it is not working .
what is the problem with it.
in my form , the name of the control "Patientnameid" is "Patient"
 
S

Svetlana

Dim strCpr As String
strCpr = Nz(DLookup("Personalnumber", "patients", "patientnameid =" &
Me!Patient))
If strCpr<>"" Then
Me![Personalnumber ] = strCpr
End If
 
G

Guest

There was a space in the field argument of the DLookup. I have taken that
out and enclosed the field name in brackets.
Since you state the name of the field on the form is Patient, I have put
that in it's proper place. Also, the reference to the variable or object
that contains the value you want to look for has to be outside the quotes.
varcpr = DLookup("[Personalnumber]", "patients", "[patientnameid] = " &
Me.Patient)
 
G

Guest

thanks alot to both of you for your fast response. I have tried both ways
..perfect.
thanks again.
 

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

Similar Threads


Top