Question

I've been looking for a bit, but haven't found a good answer. I've found that I could generate the code in a VBA procedure and run it from there, however, i'm working on someone else's design and don't want to change it up too much.

In part of that pass-through query we have something like this:

WHERE (((ID='380')

I want the 380 to be code that will look at a UserForm combo box, write a query for my database returning a value WHERE column = combobox.value

I hope that makes sense, let me know if anyone know's how to work with this. Thanks.

Was it helpful?

Solution 2

After looking around a lot and researching a bit it seemed that only a stored procedure on the server (Which I cannot do) or creating a string and passing that string to the pass-through query are my options. I'm going to pursue the string option since it seems like the best option with my constraints here. if anyone comes up with any idea's later on that would help, let me know. Thanks.

OTHER TIPS

You can set the combobox to put the selected value in a cell, and then link the query to the value of that cell via a parameter.

Cheers -

One way would be to store a template query in a pass through query, say:

select * from table where ID = [ID]

Then use VBA to read the query, substitute the ID, write it out to another prepared query, and execute it. Something like this:

Sub zzz()

    Dim SQL As String

    With CurrentDb
        SQL = .QueryDefs("PassThruQueryTemplate").SQL
        .QueryDefs("PassThruQuery").SQL = Replace(SQL, "[ID]", "380")
        .Execute "PassThruQuery"
    End With

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top