SpectacledBear
Programmer
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
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