Hi,
Looking for some guidance as I am not really sure how to handle this. I have an event on my form with a loop, and I nearly have everything perfect (well in my eyes J ). I am not sure how to refresh/reload my form from within my code.
The code below is what I would deem a successful event.
This code is triggered from Form1(I know bad name). Ideally when we get to this the MsgBox (which I will eventually disable). I am looking for some sort of pop up message that will auto close after x seconds, then my main form Form1 would auto refresh with the focus on cboMasterASN of the main form, to allow the user to start working on the next order.
I have tried timers, procedures etc but seem to be getting all sorts of errors. I think because I am trying to execute these commands from within my loop/statement. Refresh and setfoucs don’t seem to work either while in the code. Can I do some sort of GoTo event to a procedure etc?
The full code is below. Thanks in advance.
Looking for some guidance as I am not really sure how to handle this. I have an event on my form with a loop, and I nearly have everything perfect (well in my eyes J ). I am not sure how to refresh/reload my form from within my code.
The code below is what I would deem a successful event.
Code:
' Display a message indicating that the update is complete
MsgBox "Status of Order With Master ASN of: " & Me.txtMasterASN & " updated to 'Shipped'
I have tried timers, procedures etc but seem to be getting all sorts of errors. I think because I am trying to execute these commands from within my loop/statement. Refresh and setfoucs don’t seem to work either while in the code. Can I do some sort of GoTo event to a procedure etc?
The full code is below. Thanks in advance.
Code:
Private Sub Form_Current()
Dim displayInputBox As Boolean
Dim valuesMatched As Boolean ' Declare and initialize to False
' Set displayInputBox to True at the beginning
displayInputBox = True
' Check if either value is null
If IsNull(Me.txtCount) Or IsNull(Me.txtQtyTray) Then
' Ignore if either value is null
' MsgBox "One or both values are null. Cannot perform the comparison."
ElseIf (Me.txtCount) = (Me.txtQtyTray) Then
' They are the Same
' Check if MasterASNValue and MasterSerialValue match tstScannedASN and txtScannedSerial
Dim MasterASNValue As Variant
Dim MasterSerialValue As Variant
Do While Not valuesMatched
Dim originalSerialValue As Variant ' To store the original value of txtMasterSerial
If displayInputBox Then
' Store the original value of txtMasterSerial
originalSerialValue = Me.txtMasterSerial
MasterASNValue = InputBox("On the Master Label Please Scan ADVICE NOTE Number(N):")
MasterSerialValue = InputBox("On the Master Label Please Scan SERIAL Number(M):")
End If
' Check if both MasterASNValue and MasterSerialValue are not null and then compare them
If Not IsNull(MasterASNValue) And Not IsNull(MasterSerialValue) Then
If MasterASNValue = Me.txtMasterASN And MasterSerialValue = originalSerialValue Then
' They match
valuesMatched = True ' Set the flag to exit the loop
Dim strSQL As String
strSQL = "UPDATE tblMasterASN SET Status='Shipped', [ScanMasterASN]='" & MasterASNValue & "', [ScanMasterSerial]='" & MasterSerialValue & "' WHERE MasterASN = '" & Me.txtMasterASN & "'"
' Execute the SQL statement to update the Status field
CurrentDb.Execute strSQL
' Display a message indicating that the update is complete
MsgBox "Status of Order With Master ASN of: " & Me.txtMasterASN & " updated to 'Shipped'"
' Open a form here
DoCmd.OpenForm "frmBlank", , , , , acDialog
' Exit the loop
Exit Do
Else
' They don't match
Dim response As VbMsgBoxResult
response = MsgBox("ADVICE NOTE Number(N) and SERIAL Number(M) do not match the scanned values. Do you want to re-enter the data?" & vbCrLf & _
"Scanned ADVICE NOTE Number(N) is: " & MasterASNValue & vbCrLf & "Scanned SERIAL Number(M) is: " & MasterSerialValue, vbYesNo)
If response = vbNo Then
Exit Do ' Exit the loop if the user chooses not to re-enter data
End If
' Set the flag to display InputBox again
displayInputBox = True
End If
ElseIf Not IsNull(MasterASNValue) Or Not IsNull(MasterSerialValue) Then
' If either MasterASNValue or MasterSerialValue is not null but the other is null, display a message
MsgBox "Both ADVICE NOTE Number(N) and SERIAL Number(M) must be entered. Please re-enter both values."
displayInputBox = True ' Set the flag to display InputBox again
End If
Loop
' Use On Error Resume Next to suppress errors during focus setting
On Error Resume Next
Me.cboMasterASN.SetFocus
On Error GoTo 0 ' Reset error handling
' Alert if too many items are packed.
ElseIf (Me.txtCount) > (Me.txtQtyTray) Then
MsgBox "Alert: Quantity loaded on the pallet is greater than the Order Quantity"
Else
' They are Different
' MsgBox "They are Different"
'Debug.Print "Last Else"
End If
'Debug.Print "Last End IF"
End Sub