Check if Textbox Text in a ComboBox

BCullenward

Registered User.
Local time
Today, 02:46
Joined
Jul 6, 2005
Messages
28
I'm having some problems finding the proper VBA syntax for checking to see if the text in a textbox is contained in a combobox. I'd know how to do this in VB.Net, but unfortunately I'm using VBA.

I have a sub-form where all the data is bound from one table, and have added a combobox to this sub-form in which it is not bound, but gets it's data from a seperate table.

The main table that has everything bound has a field called "Type" that has user entered data, and several hundreds of records that have variations of the spellings or type, so I have made a seperate table that contains a list of the 8 or so main "Type"s, including one for Other which is not found in the Type field for the main table.

What I want to do is check to see if the value of the bound textbox of Type is one of the types in the Combo box, if it is I want to have the textbox be blank, the combobox's type to be selected.

If the type is not found in the combobox's list, I want to have the combobox to display "Other", have the bound textbox remain as it is with the type in it. Under this condition, if the textbox's text is misspelled and then corrected, or if a different value is picked from the combobox, it needs to change to the condition of where the textbox text is found in the combobox list.

On the update, it needs to change the textbox text back (as it's bound) to the value of the combobox text (unless the combobox is of type other, in which case it'll simply remain as the textbox value).

So, my question is how can I determine if the value of a textbox is listed in a combobox, and are there any other potential problems I should take into consideration?

I'm planning on doing all the loading on the Form Load event, and on the Form UnLoad Event I will put the value of the combobox back into the textbox.
 
If the user enters data, you have the Before Update Event/After Update event.


After update, put the value of the text box in a variable, compare it in the combo box, etc.

Start testing it.

After Update event
msgbox me.textbox.value.

------------

then create a variable

Its a whole programming code, you might want to look at sample codes in Access or search this site.
 
Code:
        Dim x As Integer
        Dim found As Boolean
        Dim strType As String
        Dim strLienType As String
        Dim cobLienType1 As ComboBox
        
        found = False
        
        With [Forms]![New Order Form]![Outstanding Mortgages or Liens].Form!
            For x = 0 To .cobLienType.ListCount - 1
                strType = .cobLienType.ItemData(x)
                MsgBox strType & " -strType"
                If .LienType.Text = strType Then
                    MsgBox "Found!"
                    found = True
                    .cobLienType.SetFocus
                    .cobLienType = .cobLienType.ItemData(x)
                    .LienType.SetFocus
                    'lientype.text = ""
                End If
            Next x
    
            If found = False Then
                'MsgBox "Not found"
                .cobLienType.SetFocus
                .cobLienType.Text = "Other"
            End If
        End With

that only pulls the numbers, but in the combobox all that is shown are the words which I want. What do I have to set strType to in order to get the text contained at index X in the combo box?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom