Results 1 to 12 of 12

Thread: running queries from VB

  1. #1
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116

    running queries from VB

    I have a sring with a stored SQL statement in it. I know I can do it, I just cant seem to figure out how to set the forms recordset equal to that string. Anyhelp anyone could give would be overly appreciated.
    Brandon

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    1. Add ADODC Control say 'MyData'
    2. change connection string property
    3. add your select statment in to the recordsource property

    If you like to change the recordsource dynamically then in the click event of your command button

    dim query as string
    query = "select name from sysobjects where name = '" & text1.text & "'"
    Mydata.recordsource = Query
    Mydata.refresh

  3. #3
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116
    Where do I put that at?

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    if you want a static result then put that query in the ADODC controls' propery window. look for recordsource.

    If you do not have ADODC control on the tool box, then right click add components and select microsoft ado control 2.7


    If you need a dynamic result. on the command button control's click even add the follwing


    dim query as string
    query = "select name from sysobjects where name = '" & text1.text & "'"
    Mydata.recordsource = Query
    Mydata.refresh


    I believe you are talking about VB.

  5. #5
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116
    If you do not have ADODC control on the tool box, then right click add components and select microsoft ado control 2.7
    Its not in my tool box, and when I went to 'more controls' and looked for it, it wasnt there. There were 900 others from microsoft, but none called microsoft ado control 2.7. Could it possibly be called something different?

  6. #6
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    in the add components you should have that.

    "Microsoft ADO Data Control 6.0 (SP4)"

    or else install MDAC 2.7 on your machine or VB Service pack

  7. #7
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116
    I feel like such an idiot sometimes. I feel like this is really simple, and im just stupid for not getting it.

    I understand I need to add an ADODC, by the way, is that supposed to be ADODB, to something, but am I adding it to my form, or to my VB code?

    If it is to my form, I do not have that control, and can not find that control, can you give me a direction to find it?

    If it is in the code, I have no idea how to use it. I have one example, but am not sure if it is the correct thing or not. It apparently has it defined as: Dim cnn as ADODB.connection. Is that a propper declaration? Is that what you are telling me to add?

    if so, all I need to do is, with above declaration, is cnn.recordsource = query?

    I know I'm starting to sound like a pain in the ass for not getting this, and I'm sorry, but I need to understand this.

    Brandon

  8. #8
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Create folder c:\Bman

    UNzip this file and read instruction.doc
    Attached Files Attached Files

  9. #9
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116
    now I see where the trainwreck is comeing into play. I am using VBA, which means that I have Access forms, and we misunderstood eachother and you thought I was actualy using a VB compiler.

    I'm using Access with VBA code. I see what you were getting at, and i see why it works in VB, but I cant add one of those controls into Access, ... atleast not that I know of.

    Thank you for all the work you put into that reply though, I appreciate it ...

  10. #10
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    "running queries from VB " triggered me that you are using VB.

    "I believe you are talking about VB."
    and you didnt deny it.

    with Access VBA

    http://www.tek-tips.com/gpviewthread...lev2/4/lev3/27

  11. #11
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116

    Some days, Access just hates me

    Ok, my search function,which worked fine at the end of last week, has stoped working all together. attached is the code i'm useing, but when you click the button all it does is set the recordsource for the form, but it has no records. If you view it in datasheet view there is nothing. But the thing that ticks me off is that if you go into the query builder from the form, and you view the query in datasheet view, it is displayed correctly.

    Meaning the code builds the query correctly, but somewhere during the implimentation things are getting all mucked up. What I don't understand though is why, without being altered or even viewed since friday, how it stoped working. If anyone can see any big glitches in the code, or anything else that would keep it from running I would appreciate some advice.

    Oh, and on the form the 4 text boxes have control source that come from the query. They just dont display anything at all.

    Brandon
    Attached Files Attached Files

  12. #12
    Join Date
    Jun 2003
    Location
    Bloomington, IN, USA
    Posts
    116
    thats it, I'm killing my boss. He went in and thought it was supposed to work useing filters, which its not, and set a filter on the form w/o telling me about it. So I just wasted 2 1/2 hours cus he doesnt know how to ask simple questions. I know the same could be said about me not asking... but hes not supposed to be playing with the form designs anyway. Well, NM, i guess I got this one figured out on my own.

    Brandon

Posting Permissions

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