Combo Box on Form

  • Thread starter Thread starter MDI Anne
  • Start date Start date
M

MDI Anne

I have placed a combo box on a form. When I scroll down with the roller on
my mouse - it works. When I click on the record selector on the bottom of
the form - it works. When I click on the drop down box to make my selection
- it doesn't work. The selection changes, but the rest of the form stays the
same.

Suggestions?

Thanx!
 
Hi Anne,
put code in the after update event of the combo box like this

cboSubcategory is the name of the combo
SubcategoryID is the name of the field in the 1st (hidden) field of the
combo

Private Sub cboSubcategory_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[SubcategoryID] = " & (Nz(Me![cboSubcategory], 0)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End if

End Sub

Jeanette Cunningham
 
I think you have spazed your data.

If the combo box is a bound control, each time you make a selection, you are
changing the value in underlying table.

Combo's used for searching should be unbound and only used for searching.
Then to make the selected record the current record, you use the After Update
event of the combo box:

If Not IsNull(Me.MyCombo) Then
With Me.RecordsetClone
.FindFirst "[MyField] = " & Me.MyCombo
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
 
Jeanette,
FYI, you should always close recordsets before exiting the procedure and set
the reference to Nothing
rs.Close
Set rs = Nothing

Most of the time, it will not be a problem, but it is good housekeeping.

And, read my response. Note I use the recordsetclone which means I don't
have to take the time and resource to create a recordset and close it.


--
Dave Hargis, Microsoft Access MVP


Jeanette Cunningham said:
Hi Anne,
put code in the after update event of the combo box like this

cboSubcategory is the name of the combo
SubcategoryID is the name of the field in the 1st (hidden) field of the
combo

Private Sub cboSubcategory_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[SubcategoryID] = " & (Nz(Me![cboSubcategory], 0)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End if

End Sub

Jeanette Cunningham



MDI Anne said:
I have placed a combo box on a form. When I scroll down with the roller on
my mouse - it works. When I click on the record selector on the bottom of
the form - it works. When I click on the drop down box to make my
selection
- it doesn't work. The selection changes, but the rest of the form stays
the
same.

Suggestions?

Thanx!
 
Back
Top