PDA

Click to See Complete Forum and Search --> : simple query using databound control and variable


Bebe
Mar 27th, 2000, 10:39 PM
I need to get the case to be pulled up from what the user inputs in an input box and then query the database with that information. I cannot get it to work. I am using an msflexgrid so all cases will appear for the same person. people can be in the database by their case number more than once -- but each complaint has its own autonumber. If you follow. So the same case number say 000000 could be in the database 10 times and I want all of those to show up in the grid, but the "000000" needs to be a variable for the query!!

here is my code i am getting a syntax error:
Private Sub Form_Load()
GetAuto$ = InputBox("Enter Case No", "PSR Input Data")
Data2.RecordSource = "SELECT * FROM MASTER WHERE CASE_NO LIKE '" & GetAuto$ & "" ' ""
End Sub

Clunietp
Mar 27th, 2000, 10:45 PM
Change this:

Data2.RecordSource = "SELECT * FROM MASTER WHERE CASE_NO LIKE '" & GetAuto$ & "" ' ""

To this:

Data2.RecordSource = "SELECT * FROM MASTER WHERE CASE_NO = '" & GetAuto$ & "'"


If you want to use a wildcard with your LIKE statement, use this:

Data2.RecordSource = "SELECT * FROM MASTER WHERE CASE_NO LIKE '" & GetAuto$ & "*'"

use a % (percent sign) for your wildcard if you are using ADO. DAO uses the * (asterisk)

[Edited by Clunietp on 03-28-2000 at 11:46 AM]

Bebe
Mar 27th, 2000, 11:14 PM
worked great thank you!!!

also if I am using a grid and would like the grid to automatically size to the longest field is there some way to do this; I would appreciate the help

thanks