Unanswered: Newbie: put search result to another form
I'm new to VBA in Microsoft Access and I have following problem:
I want to search people with lastname "Smith*" in main form and if the result return 2 people or more, it will automaticcaly open "search result form" and display the result in listbox created in "searchadvanced".
I did as follow:
In main form, I created a following code:
Dim rs As New Recordset
Dim hanh As DAO.Recordset
"select customerid from customers where " & _
"lastname like '" & locate & "%'", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If rs.EOF Then
MsgBox "khong tim thay " & locate & "."
If rs.RecordCount > 1 Then
OpenArgs:="lastname like '" & locate & "*'"
Set hanh = Me.RecordsetClone
hanh.FindFirst "lastname like '" & locate & "*'"
Me.Bookmark = hanh.Bookmark
then I created button "Find Smith" in mainform and put following code in event click:
then I created a form named "searchadvanced" and created a listbox named "names" in it, and in load event of "searchadvanced" I put following code:
Private Sub Form_Load()
.RowSource = _
"select customerid, " & _
"lastname & ', ' & firstname as name, " & _
"city & ', ' & state as location" & _
"from customers where " & Me.OpenArgs
.ColumnCount = 3
.ColumnHeads = True
.ColumnWidths = "1;1.5 in;1.5;"
And when I click "Find Smith" in main form, it opened "searchadvanced" form, but no result appeared. It don't work for me. I attached a exampled file for you to see is something wrong there.