Trouble

Ken_C

Registered User.
Local time
Yesterday, 19:07
Joined
May 22, 2006
Messages
11
I have a timed form that opens when my db loads. When the form closes a query is run that pulls time sensitive records from a customer table.

I am trying to set up another function on my form that takes the system date from a text box on my form(already made) and compares it to a field in a query I have set up. If the fields match it should run report containing all of the fields where the dates match.

My code is similar to this...

Private Sub Form_Load()
If frmWelcome("txtDATE") = qry30_DAY_ALERT("30_DAY") Then
DoCmd.OpenReport "Report Name"
End If
End Sub


***frmWelcome = loading form
txtDATE = text box that displays the system date
qry30_DAY_ALERT("30_DAY") = query and field that contains the date a customer should be contacted.


Its simple, but I keep getting different errors. Can someone help me or make a suggestion on a better way to set this up.

Thanks in Advance
 
What do you mean by "system date"? Are you using Date() to populate this control or Now()? Now() includes time and so will usually cause undesirable results when used to compare to other date fields. Does the 30_Day field contain a date or date + time.

When you have a time component with your date and you want to compare just the date part, you can use the DateValue() function to extract only the date part.
 
I'm using Date(). I tried setting it up a different way, but I get no result here is my 2nd attempt.

**User is supposed to enter current Date in "txtDate" text box then press Date_Toggle button.**

Private Sub Date_Toggle_Click()

DoCmd.OpenQuery "qry30_DAY_ALERT"
If [Forms]![frmWelcome]![txtDate] = Me.[30Day] Then
DoCmd.OpenReport "rpt30_Day_Out"
DoCmd.RunMacro "mcrClose_Welcome"
End If

Date_Toggle = Null

End Sub


*** Me.[30Day] is a field in the query qry30_DAY_ALERT ***


The only part of the code that runs is the OpenQuery, even if the txtDate and "30Day" field are equal.

Any suggestions
 
Last edited:
Your code is not looking at the recordset created by the query if that's what you are thinking. Use a DLookup() or open a recordset using DAO or ADO.
 

Users who are viewing this thread

Back
Top Bottom