简体   繁体   中英

Editing Passthrough SQL Query with Replace in Microsoft Access VBA

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM