Solved

DCOUNT Query

Posted on 2014-04-16
3
247 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

790 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