I have an Issue with event DropDown in combobox in Access's form

Copper Contributor

In a form, I have a combo box that changes dynamically, i.e., during execution each time I select it. Everything works fine except for the DropDown, which does not "auto-expand." I am sending the code I am using, thanks

 

Option Compare Database

Dim Seleccion As Integer

Const MarcaSQL1 As String = "SELECT pres_marca.Marca FROM pres_marca;"
Const MarcaSQL2 As String = "SELECT pres_modelo.Descripcion FROM pres_modelo WHERE (((pres_modelo.marca)=[textomarca]));"
Const MarcaSQL3 As String = "SELECT pres_cisterna.descripcion, pres_cisterna.Marca FROM pres_cisterna WHERE (((pres_cisterna.Marca) = [Textomarca])) ORDER BY pres_cisterna.Cisterna;"


Private Sub Form_Current()
    Seleccion = 1
    Caracteristicas.RowSource = MarcaSQL1
    Caracteristicas.Requery
End Sub

Private Sub Caracteristicas_AfterUpdate()
    
    If Seleccion = 1 Then
        Textomarca = Caracteristicas
        Seleccion = 2
        Caracteristicas.RowSource = MarcaSQL2
        Caracteristicas.RowSourceType = "Table/Query"
        Caracteristicas.Dropdown
    
    ElseIf Seleccion = 2 Then
        Textomodelo = Caracteristicas
        Seleccion = 3
        Caracteristicas.RowSource = MarcaSQL3
        Caracteristicas.Requery
        Caracteristicas.Dropdown
    
    ElseIf Seleccion = 3 Then
        TextoCisterna = Caracteristicas
        Seleccion = 1
        Caracteristicas.RowSource = MarcaSQL1
        Caracteristicas.Requery
        Caracteristicas.Dropdown
    
    End If
    
End Sub

 

2 Replies
I would move this line outside the If ... End If structure.
...
End If

Caracteristicas.Dropdown

And I would do that anyway. Why repeat the line multiple times.

@aramirezferrer i would utilize the Timer Event to change the recordsource.