Clear Combobox

acsuser1

Registered User.
Local time
Today, 12:53
Joined
Aug 27, 2014
Messages
16
I have a simple form with two comboboxes, one for badge id and one for equipment id. There is one textbox which is for the action being performed. The user will use a scan gun to populate each of these by scanning the barcode on their badge, the equipment, and a label for the action. The form works fine when the proper barcode is scanned for each field. So, now I am trying to catch errors.

When an invalid barcode is scanned for the badge id combobox the dropdown shows. I would like to know how to now show the dropdown as well as clear what was scanned into the badge id combobox. Very new to the coding side of Access though I have worked with them and built several myself. Any ideas? Thank you
 
Presuming your barcode scanner sends the "enter" command after the scanned number, then I think you need to set the combobox "Limit to List" property to "Yes" this will force the comboboxes "Not In list" event to run.

You can then use the "Not in List" event to clear the combobox.

There is a good example Here:- Introduction to Data Entry about halfway down the page.
 
Great tutorial you provided. Thank you. Do I have the code right? I am now getting a "Label not defined" error.


Private Sub cmbEXEID_NotInList(NewData As String, Response As Integer)
On Error GoTo cmbEXEIDNotINList_Error
Dim NewcmbEXEID As Long

If IsNull(cmbEXEID) Then
cmbEXEID = ""
Else
NewcmbEXEID = cmbEXEID
cmbEXEID = Null
End If
End Sub
 
Don't forget to use code tags!

Try this:-

Code:
    If IsNull(Combo5) Then
        ' Set the value of the combo box empty
        Combo5 = ""
    Else
        Combo5 = Null
    End If
    
            ' The combo box is ready to receive a new value.
            If MsgBox("The Value '" & NewData & "' does not exist. Click YES to Continue", vbYesNo) = vbYes Then
                      
               MsgBox " >>> " & "I Clicked YES"
            
                'Refresh the Combo5 combo box
                Combo5.Requery
                Combo5.Dropdown
                
               ' Assuming that the Data was added, ignore the error
                'Response = acDataErrAdded
                 Response = acDataErrContinue
            Else
                ' If the Data was not added, indicate an error
                Response = acDataErrContinue
            End If
 
I am still getting a "label not defined" error. The first line of code below is what highlights when the error runs. Here is the code I entered:
Code:
Private Sub cmbEXEID_NotInList(NewData As String, Response As Integer)
On Error GoTo cmbEXEIDNotInList_Error
    
    If IsNull(cmbEXEID) Then
        ' Set the value of the combo box empty
        cmbEXEID = ""
    Else
        cmbEXEID = Null
    End If
    
        ' The combo box is ready to receive a new value
        If MsgBox("The Value ' " & NewData & "' does not exist. Click Yes to Continue", vbYesNo) = vbYes Then
            MsgBox " >>> " & "I Clicked Yes"
            
                'Refresh the cmbEXEID combo box
                cmbEXEID.Requery
                cmbEXEID.Dropdown
                
                'Assuming that the data was added, ignore the error
                    'Response = acDataErrAdded
                    Response = acDataErrContinue
        Else
            'If the data was not added, indicate an error
            Response = acDataErrContinue
        End If
End Sub
 
The label name is not the same as the control name. Correct and problem will go away.
 
The name of the combobox is cmbEXEID. Can you explain what you mean by control name? I had a textbox (named txtEXEID) over the cmbEXEID but when I removed that I still got the same error. I also have another combobox (cmbEquipID) without a textbox over this one and I placed the same Not In List Event code for this but still got the same error.
 
You most likely need to refer to name of the textbox and not the control source it is bound to.
Also, try (Me.cmbEXEID) = ""
 
That worked to clear the label not defined error. Thank you. If the entries are okay can I put that code in the Not In List event or do I need to have a Before or After Update event as well? When the EXE ID is valid I have a green check mark replacing the red x. Something like this:

Code:
Private Sub txtEXEID_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cmbEXEID_NotInList
    If [txtEXEID] = [cmbEXEID] Then
        imgYesEXEID.Visible = True
        imgXNoEXEID.Visible = False
    
    ElseIf IsNull(txtEXEID) Then
           
    'If IsNull(cmbEXEID) Then
        ' Set the value of the combo box empty
        Me.cmbEXEID = ""
    Else
        Me.cmbEXEID = Null
    End If
    
        ' The combo box is ready to receive a new value
        If MsgBox("The Value ' " & NewData & "' does not exist. Click Yes to Continue", vbYesNo) = vbYes Then
            MsgBox " >>> " & "I Clicked Yes"
            
                'Refresh the cmbEXEID combo box
                Me.cmbEXEID.Requery
                Me.cmbEXEID.Dropdown
                
                'Assuming that the data was added, ignore the error
                    Response = acDataErrAdded
                    Response = acDataErrContinue
        Else
            'If the data was not added, indicate an error
            Response = acDataErrContinue
        End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom