Results 1 to 19 of 19

Thread: SQL Strings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Lightbulb

    Ok i got a button to execute a search and display the results on a flexigrid but VB doesnt like it for some reason.........Please help cos i have no idea where i have gone wrong.

    Private Sub cmdSearchBand_Click()

    Dim bandsql As String

    bandsql = "Select * from cd_serial_numbers where (band_name ='" & txtband.Text & "')"

    msflexigrid1.DataSource = bandsql
    msflexigrid1.Refresh

    End Sub


    Could someone please tell me where i have gone wrong......
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    What is the exact error you are getting?


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    The error that i get is
    Run-Time Error '424'

    Object Required
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Do you have an ADO Data Control on the form?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    No there isnt a data control

    So i link the flexigrid to the data control and then run the SQL string, yeah?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  6. #6
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    If you want the ADO data control you must add it from the Components. It's Microsoft ADO Data Control 6.0 and add the Reference to Microsoft ActiveX Data Objects 2.0 Library.

    Set the DataSource of the Flexgrid to the Data Control and then set the RecordSource of the Data Control to your SQL statement and do your refreshes.

    That should work, it's late...


  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    Ok now the flexigrid displays the whole table....but now the error comes up when i try to search for a record.

    Same error as before
    Run-Time Error '424'
    Object Required

    it must be the SQL string...
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  8. #8
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    If it was the SQL string VB would give a Syntax error in SELECT statement.

    Did the ADO Data Control test properly when you set it's properties?

    Did you include the refernce to the Microsoft ActiveX Data Objects 2.0 Library?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Exclamation

    Ok the ADO Data Control tested fine
    and i did include the reference to the ActiveX Data Object Controls 2.0

    but i still get the same error......

    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  10. #10
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411
    That error you get is I think because you are not using the DataSource property correctly.

    The code you gave shouldn't work even after following the advice of Psyrus because DataSource is not a string. When I try your example I get a Type Mismatch error as I would expect.

    If you plan to use the MSFlexGrid, then you must first put a "Data" control onto your form. Then set the Datasource property of the MSFlexgrid to the data object (it will appear in the dropdown for the DataSource property).

    I think you have already done this. Next, you may change the RecordSource property of the Data object in code or at design time. You must then refresh the Data object to "run" the query.

    that is,
    Data1.RecordSource="Select * from Table"
    Data1.refresh

    You do not even have to touch the msf control. It will be updated automatically.

    Note that you can also set the recordsource property to the name of a table or query as well.

    that is,
    Data1.RecordSource = "myTable"
    Data1.refresh

    This has the same effect as the first syntax.

    If this still doesn't work or make sense, you might have to write more description of which line the error happens on and what the settings of the properties I have mentioned are.

    Regards
    Paul Lewis

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    Ok i followed your instructions and got rid of the ADO stuff and just put the plain data control in...
    I linked it all up and ran it. Tried to search for a band name...and up came an error.....

    Run-Time error '3078'

    Microsoft Jet Databases cannot find the table or query "". Please make sure it exists and that its name is spelt correctly....

    now what?
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    i am sorry i only saw PaulLewis's reply i tried your's Aldea now i just a problem of a syntax error which is nice.....It says

    Syntax error in FROM clause

    i think it is the Command Tyep in the recordsource tab of the adodc's properties. What should it be??
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132

    Exclamation

    None of these work for me.....

    PLEASE HELP anyone else w/ a different idea
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  14. #14
    Member
    Join Date
    Jun 2000
    Location
    Perth Western Australia
    Posts
    41

    Cool

    Check out my reply to 'FLL' on a similar problem to yours. It is related to the data environment, however it is just the same if you have used ADO code.

    http://forums.vb-world.net/showthrea...threadid=22548

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    i read FLL thread but i dropped the ADO cos i just couldn't get it to work. The problem lies in executing the SQL string onto the recordsource...

    the exact problem is that the data control does not want to refresh after the sql has been executed on it.


    C'mon there has got to be a simple answer for this.

    [Edited by Harrild on 07-14-2000 at 07:50 PM]
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  16. #16
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Harrild,

    I have had similar problems like this. That's why in my post I said do your refreshes. I tried refreshing everything until it worked, the data control, the grid and the form. One of them will work. I just wish I remembered how I did it in class.

    PaulLewis

    I didn't say to set the DataSource to the string, I said the RecordSource of the DataControl in my last post. But the previous posts kinda explain it alot better than I could.


  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    Thanks for your last post Psyrus...looks like i am going to spend all my school lunches and recesses at the computer rooms (yes i am doing this for a school assessment and yes its my major work for my final year computer exams - i am an accelerated student) trying to get this right but i'll still be posting.

    If at anytime your remember how u did it could you post it here or email it to me [email protected]

    i got the everything to work cept the refreshing of the msflexigrid (doh!)
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    132
    my code now looks like this:

    dim bandsql as string
    bandsql = Select * from [cd_serial_numbers] where [band_name] = '" & txtband.Text & "'"
    data1.recordsource = bandsql
    data1.refresh

    the last line doesn't work though.....doh!
    Reality is an illusion caused by by lack of drugs

    Is this real or am i just having a dream?

  19. #19
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Harrild,

    Check your Yahoo email. I sent you a sample DAO project to try out. It should work without SP3.
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

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