|
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. |