help with code
I've created a search form where the user presses a command button and the possible matches are displayed in a list box. The user should then be able to click on the correct response in the list box to bring up the correct record in a form. I've used the following code posted here by Mile-O-Phile or Phil Hartman but I can't seem to get it to work properly. When the user clicks on the list box, a form is opened and displays all records rather than just the one that is needed. The unique id in my form is in the first column of my table.
Option Compare Database
Option Explicit
Private Sub cmdSearch_Click()
If IsNull(Me.txtFilter) Then
MsgBox "You have not entered any filter criteria.", vbExclamation, "Title"
Exit Sub
End If
With lstResults
.RowSource = "SELECT * FROM Booking WHERE [Last] Like '*" & Me.txtFilter & "*';"
.Requery
End With
End Sub
Private Sub lstResults_AfterUpdate()
DoCmd.OpenForm "Booking", acNormal, "[Booking Sheet Number] = " & lstResults.Column(0)
End Sub
Thanks for the help.
I've created a search form where the user presses a command button and the possible matches are displayed in a list box. The user should then be able to click on the correct response in the list box to bring up the correct record in a form. I've used the following code posted here by Mile-O-Phile or Phil Hartman but I can't seem to get it to work properly. When the user clicks on the list box, a form is opened and displays all records rather than just the one that is needed. The unique id in my form is in the first column of my table.
Option Compare Database
Option Explicit
Private Sub cmdSearch_Click()
If IsNull(Me.txtFilter) Then
MsgBox "You have not entered any filter criteria.", vbExclamation, "Title"
Exit Sub
End If
With lstResults
.RowSource = "SELECT * FROM Booking WHERE [Last] Like '*" & Me.txtFilter & "*';"
.Requery
End With
End Sub
Private Sub lstResults_AfterUpdate()
DoCmd.OpenForm "Booking", acNormal, "[Booking Sheet Number] = " & lstResults.Column(0)
End Sub
Thanks for the help.
Last edited: