Allow Duplicate Entries in a Combo Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AXESMI59
    New Member
    • Sep 2008
    • 10

    Allow Duplicate Entries in a Combo Box

    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.

    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
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    What's the control source for your combo box?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      It sounds like you may have designed the table with a unique index on the date field.

      If this isn't the case then please try to explain your problem more clearly with relevant error messages where appropriate.

      Comment

      • AXESMI59
        New Member
        • Sep 2008
        • 10

        #4
        I resolved the issue by creating a table to place those values in. We also went with just text boxes. If the user needs to view what they entered, I have a button that will load it into a ListView control. I found a great Function for populating a ListView Control. All you have to do is call it and send an SQL Statement to it. Real slick.

        Thanks for your reply.

        Comment

        • AXESMI59
          New Member
          • Sep 2008
          • 10

          #5
          My project has many tables. I did not initially design the table structure. They use a Primary Key and Foreign Key. I split the database for Multi User usage.

          Comment

          Working...