473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem referencing the form that a Dcount and If...Then...Else statement are place in

I want to create a Dcount and an If...Then...Else statement to count
the number of records in a table based on the date that is entered to
run the form. The If....Else statment comes in because if the amount of
records for a particular date is positive, i want the form to stop
running, if there are no records that contain the date in question,
then it should continue to run the form. The problem i'm having is
referencing the date that is entered in the form in order to execute it
in the first place.
To better explain, the execution of the frmDlgDates requires a
"FromDate" and "ToDate" to be entered. The form then runs the queries
which then append the data to tables. The tables will contain the date
that was entered as the "ToDate". for example:

"FromDate" : 01/04/2005
"ToDate" : 30/04/2005

qry runs and populates a table called [tblQReturns]. the table now
contains x number of records with the date 30/04/2005.

the code i think will look something like (but the problem i'm having
is in referencing the "ToDate" that is entered in the form in the first
place. Also the dates I enter as From and To will be different each
time, so I can't build the expression with the exact date i'm looking
for):

If (Dcount("[Date]","tblQReturns","[Date] >0" &
Forms!frmdlgDates!ToDate) Then
Exit Sub

ElseIf (Dcount(("[Date]","tblQReturns","[Date] =0" &
Forms!frmdlgDates!ToDate) Then
DoCmd.OpenQuery "qryQReturns", acNormal, acEdit

End If
End Sub

is it a problem that the form i'm referencing is the form i'm trying to
execute? If anyone could help me with this problem I would greatly
appreciate it.

Nov 13 '05 #1
6 2433
I didnt follow excatly what you are doing, but this syntax is what you
are looking for. Jet requires dates to be delimited with # and the
format to be in month-day-year:

Dcount("[Date]","tblQReturns","[Date] > #" &
format(Forms!frmdlgDates!ToDate,"mm/dd/yyyy") & "#")

Nov 13 '05 #2
thanks for the tip.
i ran this expression and it worked, but i'm not exactly sure if it
worked the way i want it to. what i'm looking for the expression to do
is:
"if the date field in the QReturns table contains >0 number of records
for that date we're running in the form, then exit the sub (b/c this
would mean that this date has previously been ran). if the date field
in the table =0 number of records for that date we're running the form
for then go ahead and run the query."
does this help clear up what i'm trying to accomplish and does it
change the expression any? thanks again for your help.

Nov 13 '05 #3
try this :

if not isnull(Dcount("[Date]","tblQReturns","[Date] > #" &
format(Forms!frmdlgDates!ToDate,"mm/dd/yyyy") & "#") ) then
exit function
else
'continue processing

Nov 13 '05 #4
this expression works if the dates have already been entered, but if
running the form with a new date, a "enter parameter values" screen
comes up asking again for the "to" date and the "from" date. when i
enter the dates again i get either an error message stating "overflow"
or "data type mismatch in criteria expression" depending on if i use a
backslash when typing in the date or not. any suggestions?
thanks again for the help.

Nov 13 '05 #5
you were sending the dcount query a null value. make sure there is a
value in the form before you call the dcount:

if not isnull(forms!frmdlgDates!toDate) then
if not isnull(Dcount("[Date]","tblQReturns","[Date] > #" & _
format(Forms!frmdlgDates!ToDate,"mm/dd/yyyy") & "#") ) then
exit function
endif
endif

Nov 13 '05 #6
nevermind. i got the expression to work correctly. thanks for all the
help.

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lee Mundie | last post by:
Hi there, Simple problem here but can't seem to fix it! Okay, I have a select list from which people choose avatars... the list is option values ie. <option>Worm</option> ...
7
by: David Shorthouse | last post by:
I am attempting to create a "new account creation" asp, but would ideally like the routine to check the Access db for an existing email address and username (called UID below). The select query...
8
by: Nothing | last post by:
I have a form based on a query. If the query returns no records the form opens blank. How do I catch this conidtion at the form load so I can stop it? Michael Charney *** Sent via...
4
by: Will | last post by:
Hi, I had a DCount within a module on records in a table where CustSuffix = 0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix (Suffix in table) = G. I can't get both...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
2
by: dan.cawthorne | last post by:
Need Some Help, In Modifing this Bit of VBA Code, This the code i use and it works but i want it to go one step further in on the open event of my main start up form If DCount("",...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.