Results 1 to 3 of 3

Thread: simple query using databound control and variable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    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

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    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]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width