+ Reply to Thread
Results 1 to 8 of 8

Thread: Using Combobox value in ADO Query.

  1. #1
    Forum Contributor
    Join Date
    09-23-2007
    Posts
    109

    Using Combobox value in ADO Query.

    I'm getting the error below when I'm trying to use a Combobox Value in my access query. I've done this in design view. In the criteria field in the referenced column in my query I've placed the below filter. The idea is that when I change the combobox the event triggers a procedure which calls the query. That query incorporates the value from Combobox50. I've also placed the code below as well.

    Not sure if my syntax is wrong. Can anybody help. Thanks

    [forms]![form1]![combo2] 'have placed this in criteria field


    Error below.
    'Invalid SQL Statement; Expected Delete, Insert, Procedure, select or Update'



    Private Sub Combo2_AfterUpdate()
    Dim rst1 As Recordset
    
    
    Set rst1 = New ADODB.Recordset
    
    rst1.Open "RefLookup", CurrentProject.Connection ' "RefLookup" is the query name.
    
    Form_Form1.Text37.Value = rst1.Fields(1)
    
    End Sub
    Last edited by danny2000; 12-04-2010 at 09:41 PM.

  2. #2
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,155

    Re: Using Combobox value in ADO Query.

    What happens when you run the query manually? Here is a video on creating a search form linked to a query. Does this help you?

    http://www.datapigtechnologies.com/f...earchform.html

    Alan

  3. #3
    Forum Contributor
    Join Date
    09-23-2007
    Posts
    109

    Re: Using Combobox value in ADO Query.

    Thanks for that. When I run the query manually a parameter box comes up and it works on its own. There's something wrong with the fact that I've referenced the combobox in the query criteria. The tutorial is great but I still get the same error.

  4. #4
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,155

    Re: Using Combobox value in ADO Query.

    Are you able to post your db with some sample data so that we can look at it and see what the issues are.

    Alan

  5. #5
    Forum Contributor
    Join Date
    09-23-2007
    Posts
    109

    Re: Using Combobox value in ADO Query.

    No worries.

    I've attached an example. All you do is select the car type in the combobox and it should give you the colour in the textbox. Though I get the error.

    thanks in advance.
    Danny2000
    Attached Files Attached Files
    Last edited by danny2000; 11-24-2010 at 03:35 AM. Reason: Adding attachment.

  6. #6
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,155

    Re: Using Combobox value in ADO Query.

    Danny,
    I have changed your form as attached in the database. I deleted your after update event and made your control source for the car-make a query. Look at the properties for the two form controls. There was no need for any VBA to make this work. You can delete the query you have as it is not needed.

    Alan
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    09-23-2007
    Posts
    109

    Re: Using Combobox value in ADO Query.

    Thanks very much for your effort. I really appreciate it.
    I've tried to make use of the combobox in the query criteria in this case as vba can be used when
    using DAO. In this case I'm using ADO and it doesn't seem to handle it at all. I've only just discovered this. I'm sure there's a way. It's just a smaller part of a big picture and I would like to try to make it work if at all possible. Your solution is a good one though and I'll definitely keep that in mind.
    Thanks for your response
    Danny2000

  8. #8
    Forum Contributor
    Join Date
    09-23-2007
    Posts
    109

    Re: Using Combobox value in ADO Query.

    Thanks again for your replies.

    The problem above accurs because you can't use a Query name as the 'Source' when opening a Recordset. Ultimately this is why it is creating an error.
    Danny2000

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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

Search Engine Friendly URLs by vBSEO 3.2.0