Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro running regardless of time when it's supposed to wait

Status
Not open for further replies.

SpectacledBear

Programmer
Mar 1, 2005
58
0
0
GB
This is the macro I have running. It is supposed to check to see if the value of txtTime is the same as the current time, and if so run either one of three macros.

The user inputs a date in to txtTime, and chooses a table to archive from lst2. However, even if the time is ten hours away, the macro is running as soon as the button is pressed. Why is this?

Private Sub cmdTime_Click()
On Error GoTo Err_cmdTime_Click

Dim db As DAO.Database

Set db = CurrentDb

Dim stDoc1 As String
Dim stDoc2 As String
Dim stDoc3 As String

stDoc1 = "mcrDeliveryArchive"
stDoc2 = "mcrOrderArchive"
stDoc3 = "mcrSalesArchive"

If Not IsNull(Me!txtTime) Or Not Me!txtTime = "" Then

If lst2 = "Deliveries" And txtTime.Value = Time() Then
DoCmd.RunMacro stDoc1

Else

If lst2 = "Orders" And txtTime.Value = Time() Then
DoCmd.RunMacro stDoc2

Else

If lst2 = "Sales" And txtTime.Value = Time() Then
DoCmd.RunMacro stDoc3

End If
End If
End If

Else
MsgBox "You have not selected a correct time to complete archives", vbCritical + vbOKOnly + vbDefaultButton1, "Error"
Me!txtTime.SetFocus

db.Close

Set db = Nothing

Exit Sub

End If

db.Close

Set db = Nothing

MsgBox "Table(s) archived successfully.", vbInformation

Me!txtTime.Requery

Exit_cmdTime_Click:
Exit Sub

Err_cmdTime_Click:
If Err = 3021 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdTime_Click
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top