Closed Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: SQL VBA Query

  1. #1
    Barn Newbie Jaykappy is an unknown quantity at this point Jaykappy's Avatar
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    4

    SQL VBA Query

    Trying to get this query to run but having issues....errors out on the FROM statememt

    I am trying to incoporate a variable in the SELECT statement...the variable is actually a field in the table

    Thoughts?


    Code:
    Dim varFieldType As String
    varFieldType = Combo85
    'MsgBox varFieldType
    
    Dim MySQL As String
    
    'MySQL = "SELECT dbo_Core2.'" & varFieldType & "' FROM dbo_Core2 GROUP BY dbo_Core2.'" & varFieldType & "';"
    

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Remove the single quotes. Because these are actual field names, you don't need them.

    Example: the above would output this as the field name in the query: dbo_Core2.'YourFieldName'

    Obviously, not what you want
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Lightning Master AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123 is a jewel in the rough AOG123's Avatar
    Join Date
    Mar 2008
    Location
    Fortress Of Solitude
    Posts
    394
    Rep Power
    7

    this should "hopefully" be cleared up in my sample on

    populate combobox from another

    thanks AOG

    let me know if you have any problems
    If i helped you, make me famous by clicking the

  4. #4
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    Check out this sample.

    I live in Illinois, so, naturually, it has more records.
    Last edited by sbenj69; March 18th, 2009 at 05:50 PM.

  5. #5
    Barn Newbie Jaykappy is an unknown quantity at this point Jaykappy's Avatar
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    4

    Thats Exactly what I have been looking for...

    I was close on my query but was missing the WHERE clause...

    I made a query in the query builder to grab jsut the unique values from that field and was going from that....
    Either way I was all mixed up....

    What you have is exaclty what I was looking for...

    THank you very much...your help is very appreciated...

    Have a great day....

  6. #6
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    well, it's kind of a tricky process when you do it that way..... heh you have to have the form control name to put in the criteria of the query, but you can't build the form control until you have the query in place. I usually build the query, then the form, then go back and edit the query to add the form controls. Very little code is needed by the way.

  7. #7
    Barn Newbie Jaykappy is an unknown quantity at this point Jaykappy's Avatar
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    4

    WAIT A SECOND....that was not it...

    Sorry about that...

    Field 1, Field2, Field3
    x c b
    x c g
    e g l

    What I have is a drop down that shows the field names
    When I choose Field 3 I want to populate the other drop down box with (b, g, l)
    THen if I change the to field1 I want the other dropdown (the same as above) to update to (x, x, e)

    That make sense?

    THanks for your patience

    and help

    I can then take these dropdowns and write them to variables to base queries off of...

    Field1 X, or Field2c etc

    THanks again

  8. #8
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    Ok, say we have 3 field names....... State, Region, City

    You're wanting a combo box to choose the field to populate the other combo box with?

    For instance in combo box 1, if I choose city, it will list all cities?
    if I choose state, it will list only the states?

    If so, that shouldn't be too hard..... I have to do some real work for a bit, then I'll see if I can come up with what you want

  9. #9
    Barn Newbie Jaykappy is an unknown quantity at this point Jaykappy's Avatar
    Join Date
    Apr 2008
    Posts
    21
    Rep Power
    4

    Yes as in your example...

    The 1st drop down will show the field names (I can hard code them if needed)
    After Update
    The 2nd Drop down needs to have ONLY the UNIQUE values from that field.

    So if you choose State the 2nd dropdown will have California, Illinois, Indiana, Ohio

    THANK YOU VERY MUCH....

  10. #10
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    You're right, it's easier to hard code the first combo box. I made mine 2 columns, the first column holding the number, the second the field name. I made the first column width 0 inches so it wouldn't display the number. It stores the number, not the field name.

    Then on afterupdate of the first combo box, I did a case statement...

    case 1 - make states visible
    case 2 - make region visible
    case 3 - make cities visible

    Here is the sample..... it's really not very difficult after you see what I've done here.
    Last edited by sbenj69; March 18th, 2009 at 05:50 PM.

Closed Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Using Dropdown List Value in Database SQL Query
    By richyrich in forum ASP Code Samples
    Replies: 0
    Last Post: April 2nd, 2008, 11:05 AM

Bookmarks

Posting Permissions

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

SEO by vBSEO