Solved

DCOUNT Query

Posted on 2014-04-16
3
248 Views
Last Modified: 2014-04-16
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

0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 40005304
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

0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40005311
If the Dcount() is in code that is in a form, then the current form reference is "Me." or "[Form]"

so:

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 ( ' )

Jim.
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 40005327
Thanks Jim and goodnight from Ireland!
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question