Hello,
I can't get my userform to close because of a combobox_exit that requires an entry.
if I comment the block out the form closes fine so I know Unload works.
I can manually close the form with the X in the top right corner but Unload me doesn't work.
Maybe there's a better way to validate the entries?
I've included a screenshot of the form as well as my current code.
I've created a sheet that has barcodes for Carrier (CARxx, SHPxx, RCPxx)
The comboboxes will only accept barcodes for their type of input but any value (except CAR, SHP, and RCP) can be manually input
The reason for the logout is that a user must enter their login information (on a module) that is passed to this form. Then they can log packages until they log out.
Any help would be appreciated.
Thanks,
I can't get my userform to close because of a combobox_exit that requires an entry.
if I comment the block out the form closes fine so I know Unload works.
I can manually close the form with the X in the top right corner but Unload me doesn't work.
Maybe there's a better way to validate the entries?
I've included a screenshot of the form as well as my current code.
I've created a sheet that has barcodes for Carrier (CARxx, SHPxx, RCPxx)
The comboboxes will only accept barcodes for their type of input but any value (except CAR, SHP, and RCP) can be manually input
The reason for the logout is that a user must enter their login information (on a module) that is passed to this form. Then they can log packages until they log out.
Any help would be appreciated.
Thanks,
VBA Code:
Private Sub LogoutButton_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Qty = 1
End Sub
Private Sub CancelButton_Click()
CarrierComboBox.Value = ""
CarrierRef.Value = ""
ShipperComboBox.Value = ""
RecipientComboBox.Value = ""
PORef.Value = ""
Qty.Value = 1
CarrierComboBox.SetFocus
End Sub
Private Sub CarrierComboBox_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
x = Left(CarrierComboBox.Value, 3)
If x = "SHP" Or x = "RCP" Or x = "RCV" Then
CarrierComboBox.BackColor = rgbPink
ErrorLbl = "Please Scan Correct code or enter a proper carrier"
ErrorLbl.BackColor = rgbPink
CarrierComboBox.SelStart = 0
CarrierComboBox.SelLength = Len(CarrierComboBox.Value)
Cancel = True
End If
End Sub
Private Sub CarrierComboBox_AfterUpdate()
enteredvalue = Left(CarrierComboBox.Value, 3)
If enteredvalue = "CAR" Then
CarrierComboBox.BackColor = rgbWhite
ErrorLbl = ""
ErrorLbl.BackColor = Me.BackColor
x = Me.CarrierComboBox.Value
Y = "*" & x & "*"
botrow = Sheets("validation").Cells(Sheets("validation").Rows.Count, 1).End(xlUp).Row
For Each compval In Sheets("validation").Range("A2:A" & botrow)
If compval = Y Then
newval = compval.Offset(0, 1).Value
CarrierComboBox.Value = newval
Exit For
End If
Next
End If
CarrierComboBox.BackColor = rgbWhite
ErrorLbl = ""
ErrorLbl.BackColor = Me.BackColor
End Sub
Private Sub CarrierComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If CarrierComboBox.Value = "" Then
CarrierComboBox.BackColor = rgbPink
ErrorLbl = "Entry Required. Scan barcode or enter Carrier Name"
ErrorLbl.BackColor = rgbPink
CarrierComboBox.SelStart = 0
CarrierComboBox.SelLength = Len(CarrierComboBox.Value)
Cancel = True
End If
End Sub
Private Sub ShipperComboBox_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
x = Left(ShipperComboBox.Value, 3)
If x = "CAR" Or x = "RCP" Or x = "RCV" Then
ShipperComboBox.BackColor = rgbPink
ErrorLbl = "Please Scan Correct code or enter a proper Shipper"
ErrorLbl.BackColor = rgbPink
ShipperComboBox.SelStart = 0
ShipperComboBox.SelLength = Len(ShipperComboBox.Value)
Cancel = True
End If
End Sub
Private Sub ShipperComboBox_AfterUpdate()
enteredvalue = Left(ShipperComboBox.Value, 3)
If enteredvalue = "ShP" Then
ShipperComboBox.BackColor = rgbWhite
ErrorLbl = ""
ErrorLbl.BackColor = Me.BackColor
x = Me.ShipperComboBox.Value
Y = "*" & x & "*"
botrow = Sheets("validation").Cells(Sheets("validation").Rows.Count, 4).End(xlUp).Row
For Each compval In Sheets("validation").Range("D2:D" & botrow)
If compval = Y Then
newval = compval.Offset(0, 1).Value
ShipperComboBox.Value = newval
Exit For
End If
Next
End If
ShipperComboBox.BackColor = rgbWhite
ErrorLbl = ""
ErrorLbl.BackColor = Me.BackColor
End Sub
Private Sub ShipperComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If ShipperComboBox.Value = "" Then
ShipperComboBox.BackColor = rgbPink
ErrorLbl = "Entry Required. Scan barcode or enter Shipper Name"
ErrorLbl.BackColor = rgbPink
ShipperComboBox.SelStart = 0
ShipperComboBox.SelLength = Len(ShipperComboBox.Value)
Cancel = True
End If
End Sub
Private Sub RecipientComboBox_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
x = Left(RecipientComboBox.Value, 3)
If x = "SHP" Or x = "CAR" Or x = "RCV" Then
RecipientComboBox.BackColor = rgbPink
ErrorLbl = "Please Scan Correct code or enter a proper Recipient"
ErrorLbl.BackColor = rgbPink
RecipientComboBox.SelStart = 0
RecipientComboBox.SelLength = Len(RecipientComboBox.Value)
Cancel = True
End If
End Sub
Private Sub RecipientComboBox_AfterUpdate()
enteredvalue = Left(RecipientComboBox.Value, 3)
If enteredvalue = "RCP" Then
x = Me.RecipientComboBox.Value
Y = "*" & x & "*"
botrow = Sheets("validation").Cells(Sheets("validation").Rows.Count, 10).End(xlUp).Row
For Each compval In Sheets("validation").Range("J2:J" & botrow)
If compval = Y Then
newval = compval.Offset(0, 1).Value
RecipientComboBox.Value = newval
Exit For
End If
Next
End If
RecipientComboBox.BackColor = rgbWhite
ErrorLbl = ""
ErrorLbl.BackColor = Me.BackColor
End Sub
Private Sub RecipientComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If RecipientComboBox.Value = "" Then
RecipientComboBox.BackColor = rgbPink
ErrorLbl = "Entry Required. Scan barcode or enter Recipient Name"
ErrorLbl.BackColor = rgbPink
RecipientComboBox.SelStart = 0
RecipientComboBox.SelLength = Len(RecipientComboBox.Value)
Cancel = True
End If
End Sub
Private Sub EnterButton_Click()
Sheets("RLogData").Unprotect Password:=""
'Application.ScreenUpdating = False
'Sheets("RLogData").Activate
Range("B2").End(xlDown).Offset(1, 0).Select
ActiveCell.Offset(0, -1).Value = Application.WorksheetFunction.Max(Range("A:A")) + 1
ActiveCell.Offset(0, 0).Value = Date
ActiveCell.Offset(0, 1).Value = Time
ActiveCell.Offset(0, 2).Value = CarrierComboBox
ActiveCell.Offset(0, 3).Value = CarrierRef
ActiveCell.Offset(0, 4).Value = ShipperComboBox
ActiveCell.Offset(0, 5).Value = RecipientComboBox
ActiveCell.Offset(0, 6).Value = PORef
ActiveCell.Offset(0, 7).Value = Qty
ActiveCell.Offset(0, 8).Value = LoginName
Sheets("RLogData").Protect Password:="", AllowFiltering:=True
'Sheets("Home Page").Activate
ActiveWorkbook.Save
'Application.ScreenUpdating = True
CarrierComboBox.Value = ""
CarrierRef.Value = ""
ShipperComboBox.Value = ""
RecipientComboBox.Value = ""
PORef.Value = ""
Qty.Value = 1
CarrierComboBox.SetFocus
End Sub
Private Sub Qty_AfterUpdate()
If Not IsNumeric(Qty.Value) Then
MsgBox "You must enter a number", vbCritical
Qty.SelStart = 0
Qty.SelLength = Len(Qty.Value)
Cancel = True
End If
End Sub