In addition to Al's suggestions, if you are only wanting to find one
customer, I would suggest you consider using a Combo Box control rather than
a List Box control. The Combo control is actually much better at this sort
of thing. It is also more user friendly because it allows them to find a
customer by typing in the name. If you set the combo box property AutoExpand
to Yes, it will follow the user's typing and position on the closest match.
Then when the user has selected a customer, add the following code to the
After Update event of the combo box. This is the most common way to do this.
Note - you will have to change the names in this sample to match the names
in your applcation:
Private Sub cboActivity_AfterUpdate()
Dim rst As Recordset
On Error GoTo cboActivity_AfterUpdate_Error
If Not IsNull(Me.cboActivity) Then
Set rst = Me.RecordsetClone
'Search the table for the value in the combo
rst.FindFirst "[Activity] = '" & Me.cboActivity & "'"
If rst.NoMatch Then
'Did Not find it in the table
If MsgBox("Add Activity Number " & Me.cboActivity _
& " To the Attribute Table", _
vbYesNo + vbQuestion + vbDefaultButton2, "Activity Not
Found") _
= vbYes Then
'Add a new record to the table
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Else
'Do Not Add a new record, Empty the combo and start over
Me.cboActivity = Null
End If
Else
'Makes the selected record the current record in the form
Me.Bookmark = rst.Bookmark
End If
End If
cboActivity_AfterUpdate_Exit:
On Error Resume Next
rst.Close
Set rst = Nothing
Exit Sub
cboActivity_AfterUpdate_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure cboActivity_AfterUpdate of VBA Document
Form_frmAttributetable"
GoTo cboActivity_AfterUpdate_Exit
End Sub
ppskidpps said:
I started a database on the access 2002 on the "order entry" template. On the
orm where u place orders i would like to install a list box that would ahve
customer names and when i click one it would put all there info in the form.
i almost got it working, i have to right click > remove filter/sorting befor
clicking a name in the list box will pull up that prsons info into the form,
how can i make it just automatically pulls up ppl i click on woth ut having
to select that option?