have a project in which I am entering Serial Numbers and Date codes into a Combo box. Serial numbers are all different. However, they could each have the same Date Code. Each Serial Number has a corresponding Date Code which I then write to a table using VBA. When I try to enter a duplicate date code, it automatically finds the duplicate and will not allow me to add it again to that combo box. How do I configure that combo box so I can enter the same date code multiple times?
I use a Command button to Add the data to both combo boxes which also adds the values to 2 listboxes.
I use a Command button to Add the data to both combo boxes which also adds the values to 2 listboxes.
Code:
' 9-26-2008
' Modified: 1-19-2009 , Combined two buttons
Dim frm As Form
' SN
Dim ctl As Control
Dim ctl1 As Control
' DC
Dim ctl2 As Control
Dim ctl3 As Control
On Error GoTo cmdAddSNErr
Set frm = Forms!frmPrimary_User_Interface '!frmPrimary_User_Interface.Form
' SN
Set ctl = frm!lstSN
Set ctl1 = frm!cboOrigSerialNum
' DC
Set ctl2 = frm!lstDC
Set ctl3 = frm!cboOrigDateCodes
'intSNDCct = ctl.ListCount
' 2-14-2009
' Did the user enter the Quantity Rejected?
If txtOrigQtyRej.Value <> "" Then
' Yes
' Did the user enter both a SN & DC
If ctl1.Value <> "" And ctl3.Value <> "" Then
' Yes
' Data entry for all of the serial numbers in this rejection notice
If intQtyRej <> ctl.ListCount And intQtyRej <> ctl2.ListCount Then ' Make sure user doesn't add more serial numbers than Quantity Rejected
'Me.lstSN.SetFocus
' SN
ctl.AddItem ctl1.Value
ctl1.Value = ""
'ctl1.Value = "" ' Clear for next entry
' DC
ctl2.AddItem ctl3.Value
ctl3.Value = "" ' Clear for next entry
lblSNCount.Caption = "SN: " & ctl.ListCount & "/" & ctl2.ListCount & " of REJ: " & intQtyRej
intSNDCct = ctl.ListCount
Else ' User exceeded Quantity Rejected
MsgBox "Serial Numbers or Date Codes entered Exceeds Quantity Rejected value [" & intQtyRej & "]" & vbCrLf & "This last Serial Number or Date Code is ignored!", vbExclamation, "Serial Number(s) entry"
Exit Sub
End If
Else ' No
MsgBox "You must enter a Serial Number and a Date Code or enter '0' if none exists!" & vbCrLf & "Please make sure you enter both before attempting to add!", vbExclamation, "SN/DC entry: Missing Data"
cboOrigSerialNum.Value = ""
cboOrigDateCodes.Value = ""
cboOrigSerialNum.SetFocus
Exit Sub
End If
Else ' No
MsgBox "You must enter the Quantity Rejected before you can add Serial Numbers and Date Codes!" & vbCrLf & "Please the Quantity Rejected!", vbExclamation, "SN/DC entry: Missing Data"
txtOrigQtyRej.SetFocus
Exit Sub
End If
Set frm = Nothing
' SN
Set ctl = Nothing
Set ctl1 = Nothing
' DC
Set ctl2 = Nothing
Set ctl3 = Nothing
ExitcmdAddSN:
On Error GoTo 0
Exit Sub
cmdAddSNErr:
Select Case err.Number
Case Else
MsgBox err.Description & strErrSect, vbCritical, "Error " & err.Number & " in cmdAddSN"
End Select
Resume ExitcmdAddSN
Comment