See the [forms]!me![customerid]  in the snippet of VBA beneath.

It gives an error ... the "me" bit is the problem.
How do I simply refer to the form I am "currently on".

(Note I do not want to hard code the name of the form).

If DCount("CustomerID", "tblDetail", "WindowCode='999'   and customerid = [forms]!me![customerid]"

Open in new window

Patrick O'DeaAsked:
Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
If the Dcount() is in code that is in a form, then the current form reference is "Me." or "[Form]"


If DCount("CustomerID", "tblDetail", "WindowCode='999'  and [customerid] = " & me.[customerid])

assumes that CustomerID is a numeric.  If it's text, then it needs to be:

If DCount("CustomerID", "tblDetail", "WindowCode='999'  and [customerid] = " & chr$(34) & me.[customerid] & chr$(34))

so that it ends up with quotes around it.  You could also do that like this:

If DCount("CustomerID", "tblDetail", "WindowCode='999'  and [customerid] = '" & me.[customerid] & "'")

Using the single quote ( ' )

Try this:

If DCount("CustomerID", "tblDetail", "WindowCode='999'   and customerid = " & me![customerid]) Then

Open in new window

If your customerid is a text field, then try

If DCount("CustomerID", "tblDetail", "WindowCode='999'   and customerid = " & chr(34) & me![customerid] & chr(34)) Then

Open in new window

Patrick O'DeaAuthor Commented:
Thanks Jim and goodnight from Ireland!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.