Adding a search field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has 4 fields bound to a table.

Acct#
Name
Company
Email

At the bottom there is a save button.

This works fine, however, I want to add a search combo box at the top so
that the user can click the drop down and select the account number and have
the fields populate accordingly on the form below. What are the steps to do
this? I already have the drop-down box pulling all acct#'s in my acctMaster
table. I can't get the auto populate to work.

I will be adding more input fields down the road but want to get it working
with just these.
 
In the AfterUpdate event of the combo box, add something similar to the
following:

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

Set rs = Me.Recordset.Clone
rs.FindFirst "[Acct#] = " & Str(Nz(Me![cboAccounts], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

This code will locate the first record that has the same account number as
the one in your combo box and then go to that record. I use this quite a bit
and it works rather well. You can use it with listboxes as well.

Hope this helps!
Diana Criscione
 
Back
Top