Dlookup related code

I

Irshad Alam

I want to click a command button and check the value I entered in the Field
is available in another table or not. I will try to write the need of my code
as below :

Dlookup("FldName","TablName",[SerialNo]=Me.SerNo)
If any record Found
Msgbox("Records were found")
Else
Msgbox("No records found")

Please advise, how to write the code to get this job done in this way.

Best regards.

Irshad
 
F

fredg

I want to click a command button and check the value I entered in the Field
is available in another table or not. I will try to write the need of my code
as below :

Dlookup("FldName","TablName",[SerialNo]=Me.SerNo)
If any record Found
Msgbox("Records were found")
Else
Msgbox("No records found")

Please advise, how to write the code to get this job done in this way.

Best regards.

Irshad

All of the arguments in a DLookUp must be a string. Your Where clause
argument is not.

If [SerialNo] is a Number datatype field:
If DLookup("FldName","TablName","[SerialNo] = " & Me.SerNo)

If it is a Text datatype, then use:
If Dlookup("FldName","TablName","[SerialNo] = '" & Me.SerNo & "'")

However, all you really wish to know is if any records for the
[FldName] already exist.

Instead of DLookUp, use DCount.


If DCount("*","TablName","[SerialNo] = " & Me.SerNo) > 0 Then
Msgbox("Records were found")
Else
Msgbox("No records found")
End If
 
I

Irshad Alam

Thanks for your reply. with try it
regards

Irshads

fredg said:
I want to click a command button and check the value I entered in the Field
is available in another table or not. I will try to write the need of my code
as below :

Dlookup("FldName","TablName",[SerialNo]=Me.SerNo)
If any record Found
Msgbox("Records were found")
Else
Msgbox("No records found")

Please advise, how to write the code to get this job done in this way.

Best regards.

Irshad

All of the arguments in a DLookUp must be a string. Your Where clause
argument is not.

If [SerialNo] is a Number datatype field:
If DLookup("FldName","TablName","[SerialNo] = " & Me.SerNo)

If it is a Text datatype, then use:
If Dlookup("FldName","TablName","[SerialNo] = '" & Me.SerNo & "'")

However, all you really wish to know is if any records for the
[FldName] already exist.

Instead of DLookUp, use DCount.


If DCount("*","TablName","[SerialNo] = " & Me.SerNo) > 0 Then
Msgbox("Records were found")
Else
Msgbox("No records found")
End If
 

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