I have this update strSQL that is working great, but I'd like to make it smarter in hopes of preventing input errors.
Here is my working code:
(Note: These items will be scanned in, or numbers typed with an "Enter" after each number, and that's the purpose of the fields with the "Scan" references.)
What I'm trying to do below is to do a check that the CUST_NUM matches the BOX_NUM (both of which will be simultaneously scanned by a barcode) before accepting the DATE_BOX_RETURN . Here is my try. This is my first attempt to write an If/Else statement so please watch me closely. :-) What I have added is indented farthest right.
Can someone please tell me what I've done wrong? Hint: Debugger takes me to Line 6.
Here is my working code:
Code:
Else
Me.txtScan_Box_Num = Me.txtScanCapture
'Box exists.
'Assign box to current customer, and set box return date=now
Dim strSQL As String
strSQL = "UPDATE tblBOX SET tblBOX.DATE_BOX_RETURN = Date()" & _
" WHERE (((tblBOX.BOX_NUM)='" & Me.txtScanCapture & "'));"
DoCmd.SetWarnings (False)
DoCmd.RunSQL strSQL
DoCmd.SetWarnings (True)
Me.subfrmBOX_RECEIVING.Requery
Me.tb_Scan_Cust_Num = ""
Me.Max_ORDER_NUM = ""
End If
What I'm trying to do below is to do a check that the CUST_NUM matches the BOX_NUM (both of which will be simultaneously scanned by a barcode) before accepting the DATE_BOX_RETURN . Here is my try. This is my first attempt to write an If/Else statement so please watch me closely. :-) What I have added is indented farthest right.
Code:
Else
Me.txtScan_Box_Num = Me.txtScanCapture
'Box exists.
'If the CUST_NUM (and matching max ORDER_NUM which updates itself instantly)
'just scanned has a record matching the BOX_NUM just scanned
If tblBOX.CUST_NUM = '" & Me.tb_Scan_Cust_Num & "' & tblBOX.BOX_NUM = '" & Me.txtScanCapture & "' Then
'Set box return date=now
Dim strSQL As String
strSQL = "UPDATE tblBOX SET tblBOX.DATE_BOX_RETURN = Date()" & _
" WHERE (((tblBOX.BOX_NUM)='" & Me.txtScanCapture & "'));"
DoCmd.SetWarnings (False)
DoCmd.RunSQL strSQL
DoCmd.SetWarnings (True)
Me.subfrmBOX_RECEIVING.Requery
Me.tb_Scan_Cust_Num = ""
Me.Max_ORDER_NUM = ""
'If the CUST_NUM just scanned doesn't match a BOX_NUM
'in an existing record, then give warning
Else
MsgBox "That box number is not assigned to that customer."
End If
End If
Can someone please tell me what I've done wrong? Hint: Debugger takes me to Line 6.
Comment