Solved

DCOUNT Query

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

770 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