2 dlookup or dao that is the question

J

JoeBo

Testing for the existence of a record in a table using a DAO recordset I am
able to successfully find true or false using the following criteria.

rcdc.FindFirst "[course] = '" & [Iname] & "' And [DelegateID] = " &
[AttendeeID]

If rcdc.NoMatch Then
MsgBox "none"
Else
MsgBox "found"

I could use this but felt that it would be neater to use a simple dlookup
with the same criteria.

x = DLookup("[course]", "[qrymtcourses]", "[course] = '" & [Iname] & "' And
[DelegateID] = " & [AttendeeID])

This returns a mismatch error. Anyone point out the error of my ways.

Any help appreciated.
 
D

Douglas J. Steele

If it works in one place, it should work in the other place.

How is x defined? If it's as a string, you'll run into problems when DLookup
returns a Null (as it will if no record is found). Change x to be defined as
a variant, or use DCount instead:

If DCount("[course]", "[qrymtcourses]", _
"[course] = '" & [Iname] & "'" & _
" And [DelegateID] = " & [AttendeeID]) = 0 Then
MsgBox "None"
Else
MsgBox "Found"
End If
 
J

JoeBo

Thanks for your reply, I had defined x as boolean, the following code would
depend on a true or false return. Dcount works just as well.
Thanks

Douglas J. Steele said:
If it works in one place, it should work in the other place.

How is x defined? If it's as a string, you'll run into problems when DLookup
returns a Null (as it will if no record is found). Change x to be defined as
a variant, or use DCount instead:

If DCount("[course]", "[qrymtcourses]", _
"[course] = '" & [Iname] & "'" & _
" And [DelegateID] = " & [AttendeeID]) = 0 Then
MsgBox "None"
Else
MsgBox "Found"
End If


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



JoeBo said:
Testing for the existence of a record in a table using a DAO recordset I am
able to successfully find true or false using the following criteria.

rcdc.FindFirst "[course] = '" & [Iname] & "' And [DelegateID] = " &
[AttendeeID]

If rcdc.NoMatch Then
MsgBox "none"
Else
MsgBox "found"

I could use this but felt that it would be neater to use a simple dlookup
with the same criteria.

x = DLookup("[course]", "[qrymtcourses]", "[course] = '" & [Iname] & "' And
[DelegateID] = " & [AttendeeID])

This returns a mismatch error. Anyone point out the error of my ways.

Any help appreciated.
 

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