1

In Access I have a SQL passthrough query that returns an entire table filtered by first name.

Example

SELECT * FROM dbo.Original_Data
WHERE first_name = 'Mike';

I am trying to write some VBA that on click of a button takes the passthrough query and replaces 'Mike' with any name I put in (this will later be done by a combo box but that's another step).

I have this where TempPT is the name of the passthrough query.

Private Sub Command12_Click()

TempPT = Replace(TempPT, "Mike", "Sam")    
DoCmd.OpenQuery "TempPT"

End Sub

This doesn't work.

Is there a way that whatever I type in where I have 'Sam' is what the passthrough query will filter by?

I am using passthrough because the DB is huge and clogs up Access.

1 Answer 1

2

You need to edit the SQL property of the query. Probably something like this:

With CurrentDb().QueryDefs("TempPT")
    .SQL = Replace(.SQL, "Mike", "Sam") 
End With

DoCmd.OpenQuery "TempPT"
Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely smashed it first time. Thanks a lot dude, plugged this in it works perfectly. Now to add that combo box in :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.