Synchronizing Form and ComboBox

G

Garfield

Hi All,

I have a small problem. I have a form which will be used to display 3 types
of records i.e. Clients, Counsellors and Volunteers.
In the Form Load I setup the row source of the combo box based on the type
of record I'm viewing. The combo is populated ok, and selecting
and entry from it afterwards updates the form correctly.

My problem is when the form is first loaded it is showing the first record
of the table and not that of the first entry in the combo box. I need a way
of updating the form to show the first record of the combo box.

Here is my code so far

Private Sub Form_Load()
Me.Combo33.RowSourceType = "Table/Query"

Select Case strDisplayUserType
Case "Counsellors"
Me.btnTest.Caption = "Counsellors"
Me.Combo33.RowSource = "qryAllCounsellors"
Me.Combo33.RowSourceType = "Table/Query"
Case "Clients"
Me.btnTest.Caption = "Clients"
Me.Combo33.RowSource = "qryAllClients"
Case "Volunteers"
Me.btnTest.Caption = "Volunteers"
Me.Combo33.RowSource = "qryAllVolunteers"
Case Else
Me.btnTest.Caption = "Viewing"
Me.Combo33.RowSource = "qryAllUsers"
End Select

Forms!Users!Combo33.Requery 'reload the combobox list
Me!Combo33 = Me!Combo33.ItemData(0) 'set the first entry in the
combobox list

End Sub

Private Sub Combo33_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[UserID] = " & Str(Nz(Me![Combo33], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Thanks for your help
Garfield
 
G

Gerald Stanley

Try the following

After the line
Me!Combo33 = Me!Combo33.ItemData(0) 'set the first entry
in the combobox list

Insert a call to the AfterUpdate method e.g.
Combo33_AfterUpdate

Hope That Helps
Gerald Stanley MCSD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top