Solved Listbox RowSource (1 Viewer)

mafhobb

Registered User.
Local time
Today, 16:05
Joined
Feb 28, 2006
Messages
1,245
I have a listbox (SearchResults) on the form "FindGuest" that uses the following rowsource:
Code:
SELECT tblReservations.ID, tblReservations.PropertyName, tblReservations.GuestName, tblReservations.CheckInDate, tblReservations.CheckOutDate, tblReservations.ReservationDate, tblReservations.Status, tblResOrigin.ResOrigin
FROM tblResOrigin INNER JOIN tblReservations ON tblResOrigin.ID = tblReservations.ReservationSource
WHERE (((tblReservations.GuestName) Like "*" & [forms]![frmPropertyHistory]![txtFindGuest] & "*"))
ORDER BY tblReservations.CheckInDate;
This pulls the search string (txtFindGuest) from the form that opens this one.

Elsewhere in this form I have a textbox (txtFind Guest) and a button (cmdFindGuest). The idea is to be able to perform more searches directly from this form after the initial one.
I have the following code in the button's on click event:
Code:
Me.SearchResults.RowSource = "SELECT tblReservations.ID, tblReservations.PropertyName, tblReservations.GuestName, tblReservations.CheckInDate, tblReservations.CheckOutDate, tblReservations.ReservationDate, tblReservations.Status, tblResOrigin.ResOrigin," _
& "FROM tblResOrigin INNER JOIN tblReservations ON tblResOrigin.ID = tblReservations.ReservationSource," _
& "WHERE (((tblReservations.GuestName) Like " * " & [Me]![txtFindGuest] & " * "))," _
& "ORDER BY tblReservations.CheckInDate;"
Unfortunately I am receiving a "Run-time error 13. Type Mismatch"
The only thing that has changed in the origin of the seach string, but it is still a string.
Why is this happening?
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:05
Joined
Sep 21, 2011
Messages
14,310
Strings need single quotes surrounding them, unless the string contains a single quote. Then it is triple double quotes or Chr().
Besides that sql is not identical in syntax?
 

Minty

AWF VIP
Local time
Today, 22:05
Joined
Jul 26, 2013
Messages
10,371
Debugging 101 : You need to put your string into a variable and Debug.Print it and the error will be fairly obvious.

You need to add single quotes around your search string, but that won't be your only problem.
The debug will help you.
 

mafhobb

Registered User.
Local time
Today, 16:05
Joined
Feb 28, 2006
Messages
1,245
Code:
MsgBox Me.txtFindGuest
MsgBox Forms!frmFindGuest!txtFindGuest.Value
Me.SearchResults.RowSource = "SELECT tblReservations.ID, tblReservations.PropertyName, tblReservations.GuestName, tblReservations.CheckInDate, tblReservations.CheckOutDate, tblReservations.ReservationDate, tblReservations.Status, tblResOrigin.ResOrigin FROM tblResOrigin INNER JOIN tblReservations ON tblResOrigin.ID = tblReservations.ReservationSource WHERE (((tblReservations.GuestName) Like ' * ' & 'Forms!frmFindGuest!txtFindGuest.value' & '*')) ORDER BY tblReservations.CheckInDate"
Still struggling. No error now, but no results either
The debig.print shows "False"
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:05
Joined
Sep 21, 2011
Messages
14,310
So you have not done what has been advised/asked? :(
Put all the select into a string variable and debug.print it.
Then if you still cannnot see the errors, you can copy and paste back here.
 

Minty

AWF VIP
Local time
Today, 22:05
Joined
Jul 26, 2013
Messages
10,371
The Debug of your concatenated SQL String would show you the problem. I really don't understand not doing it.

It would show you some unwanted spaces in your criteria.
 

mafhobb

Registered User.
Local time
Today, 16:05
Joined
Feb 28, 2006
Messages
1,245
So you have not done what has been advised/asked? :(
Put all the select into a string variable and debug.print it.
Then if you still cannnot see the errors, you can copy and paste back here.
I think that I did, but I am not sure of the process/syntax.
I basically did this:
Code:
Debug.Print a = "SELECT tblReservations.ID, tblReservations.PropertyName, tblReservations.GuestName, tblReservations.CheckInDate, tblReservations.CheckOutDate, tblReservations.ReservationDate, tblReservations.Status, tblResOrigin.ResOrigin FROM tblResOrigin INNER JOIN tblReservations ON tblResOrigin.ID = tblReservations.ReservationSource WHERE (((tblReservations.GuestName) Like  ' * ' & 'Forms!frmFindGuest!txtFindGuest.value' & ' * ')) ORDER BY tblReservations.CheckInDate"
On the inmediate window I see "false"
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:05
Joined
Sep 21, 2011
Messages
14,310
StrSql = "SELECT ......"
DEBUG.PRINT StrSql

See link in my signature for basic debugging, which you have to do, if you ever want to write code that works as intended.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:05
Joined
May 7, 2009
Messages
19,245
you try:
Code:
Me.SearchResults.RowSource = _
"SELECT tblReservations.ID, tblReservations.PropertyName, tblReservations.GuestName, " & _
"tblReservations.CheckInDate, tblReservations.CheckOutDate, " & _
"tblReservations.ReservationDate, tblReservations.Status, tblResOrigin.ResOrigin " & _
"FROM tblResOrigin INNER JOIN tblReservations " & _
"ON tblResOrigin.ID = tblReservations.ReservationSource " & _
"WHERE (((tblReservations.GuestName) Like '*" & Forms!frmFindGuest!txtFindGuest & "*')) ORDER BY tblReservations.CheckInDate"
 

mafhobb

Registered User.
Local time
Today, 16:05
Joined
Feb 28, 2006
Messages
1,245
Thank you everyone.
Gasman: Looking at the debuggin videos.
arnelgp: From my last try, it was the single and double quotations and their location in the "Like ....." that was messed up. Thanks!
 

Users who are viewing this thread

Top Bottom