Solved

DCOUNT Query

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now