Results 1 to 6 of 6

Thread: ADO refresh problem

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    10

    ADO refresh problem

    I was looking through my book to see how to use SQL query statements to change the recordsource.

    My first question is... what would be the syntax to make the search criteria be whatever text was entered from a textbox?

    ie. Let form1.ado1.recordsource = "SELECT * FROM data WHERE month = 'txtMonth.text'"

    That's what I am using, but after entering txtMonth and the period it doesn't pop up a list of options so I am assuming it's not recognizing it as and object...

    And i've tried something along the lines of "SELECT * FROM data WHERE month = 'January'"

    And when I run it I get an error message saying

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

    Then another box pops up stating that form1.ado1 was unable to be refreshed...

    What am I doing wrong?

    Thanks for the help

    Herb Moyer
    Last edited by Gadreel; May 25th, 2001 at 09:46 AM.

  2. #2
    nullus
    Guest
    When you pass the value of a textbox or variable or whatever into string, you gotta concatinate it, ie. do this:

    Code:
    ado1.RecordSource = "SELECT * FROM Data WHERE Month = '" & txtMonth & "'"
    ado1.Refresh
    Also, it may be coming up with an error message, cos you've used the name 'month' as a field name, which is also a SQL function, try this:

    Code:
    ado1.RecordSource = "SELECT * FROM Data WHERE [Month] = '" & txtMonth & "'"
    ado1.Refresh

  3. #3
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Do it like this:
    Code:
    form1.ado1.recordsource = "SELECT * FROM data WHERE month = '" & txtMonth.text & "'"

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    10

    hrmm still not working

    I took the advice as far as the syntax of the text box data entry... that works fine... now when i type txtMonth and the period, the options box pops up...

    But I am still getting that error message...

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

    I have no idea what is causing that...

    just to make sure it is this...

    SELECT * FROM <name of table in database> WHERE ...

    correct?

    I only have 1 table in my database called Data so I dont see why it'd be confused

  5. #5
    nullus
    Guest
    Try putting the brackets around both names, ie.

    Code:
    SELECT * FROM [Data] WHERE [Month] = '" & txtMonth & "'"

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    10
    Originally posted by nullus
    Try putting the brackets around both names, ie.

    Code:
    SELECT * FROM [Data] WHERE [Month] = '" & txtMonth & "'"
    Ahhhhhh I figured out what it was! I feel stupid now...

    In the ADO control there is a property called CommandType...

    I had it set to adCmdTable and the RecordSource was data
    I changed the CommandType to adCmdText and set the RecordSource to SELECT * FROM data and now my queries work fine!

    Thank you guys for all the help, I really appreciate it!

    Herb Moyer

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