Dear all,
I have multiple tables (Desktops and Telephones)
A search form, to search into those tables (It searches by "User")
The search form contains a listbox that shows results (listPC)
And the following code:
It works, but I have one problem. It only shows telephones or desktop, not both. It deppends on which line inside UpdateList is first.
That example searches into 2 tables:
-Telephones
-Desktops
And searches by "user".
I want to list all telephones and desktops that a user has assigned.
What should I change to show both results?
Thanks,
Sur.
I have multiple tables (Desktops and Telephones)
A search form, to search into those tables (It searches by "User")
The search form contains a listbox that shows results (listPC)
And the following code:
Code:
Option Compare Database
Dim strUserPC As String, strUserTel As String
Dim db As DAO.Database, rsUserPC As DAO.Recordset ', rsUserTel As DAO.Recordset
Private Sub txtSearch_LostFocus()
strUserPC = ""
strUserTel = ""
strUserPC = "SELECT ALL Desktops.Serial " _
& "FROM Desktops " _
& "WHERE Desktops.User LIKE '" & "*" & Me.txtSearch.Value & "*" & "' " _
& "ORDER BY Desktops.Serial"
strUserTel = "SELECT ALL Telephones.Serial " _
& "FROM Telephones " _
& "WHERE Telephones.User LIKE '" & "*" & Me.txtSearch.Value & "*" & "' " _
& "ORDER BY Telephones.Serial"
Me.listPC.AddItem Item:="User;Device", Index:=0
Me.listPC.AddItem Item:=Me.txtSearch.Value, Index:=1
Set db = CurrentDb()
Set rsUserPC = db.OpenRecordset(strUserPC)
Set rsUserTel = db.OpenRecordset(strUserTel)
If (rsUserPC.RecordCount > 0) Then
UpdateList
End If
If (rsUserTel.RecordCount > 0) Then
UpdateList
Else
MsgBox "No results", vbOKOnly, "No results"
Me.txtSearch.SetFocus
End If
rsUserPC.Close
rsUserTel.Close
Set db = Nothing
End Sub
Sub UpdateList()
Me.listPC.RowSource = strUserPC
'Me.listPC.RowSource = strUserTel
End Sub
It works, but I have one problem. It only shows telephones or desktop, not both. It deppends on which line inside UpdateList is first.
That example searches into 2 tables:
-Telephones
-Desktops
And searches by "user".
I want to list all telephones and desktops that a user has assigned.
What should I change to show both results?
Thanks,
Sur.
Last edited: