populate combobox with default values

abenitez77

Registered User.
Local time
Today, 02:29
Joined
Apr 29, 2010
Messages
141
I saved the values of 3 comboboxes to a table and when the form opens, I want those values (default) to be populated in the comboboxes. I tried doing it like this below...but I get a run-time error 424 (object required).

Me.cmb_Projects.Column(1) = rs!DefProject
Me.cmb_Projects.Column(0) = rs!DefProjectid
Me.cmb_Periods.Column(1) = rs!DefPeriod
Me.cmb_Periods.Column(0) = rs!DefPeriodid
Me.cmb_Options = rs!DefOptions
 
Try:-
Me.cmb_Projects.DefaultValue = rs!DefProjectid
 
Me.cmb_Projects = rs!DefProjectid
Me.cmb_Periods = rs!DefPeriodid
Me.cmb_Options = rs!DefOptions
 
Code:
Private Sub Form_Load()
    Dim i As Integer
    '
    ' your code that opens the recordset somewhere here
    ' ...
    ' ...
    ' ...
    With Me.cmb_Projects
        For i = 0 To .ListCount - 1
            If .Column(0, i) = rs!DefProjectID And .Column(1, i) = rs!DefProject Then
                .value = .ItemData(i)
                Exit For
            End If
        Next
    End With
    With Me.cmb_Periods
        For i = 0 To .ListCount - 1
            If .Column(0, i) = rs!DePeriodID And .Column(1, i) = rs!DefPeriod Then
                .value = .ItemData(i)
                Exit For
            End If
        Next
    End With
    Me.cmb_Options = rs!DefOptions
End Sub
 

Users who are viewing this thread

Back
Top Bottom