jcro001
jcro001

Reputation: 17

Save query using VBA

I have form with multiple textboxes that are used to filter Subforms. The Subform Source Objects are queries. In order to filter the Subforms I update the query SQL and reassign the query as the source object on the subform.

Set qdf = db.QueryDefs("MyQuery")
qdf.SQL = strNewSQL
mySubForm.SourceObject = "Query.MyQuery" 

The filtering works correctly. However when I close my form, I get a message asking if I want to save changes to the queries. How can I avoid this message?

Edit:- Following comment by @June7, closing form using

DoCmd.Close acForm, "MyForm", acSaveNo

solved my issue.

It is also possible to close the form using an embedded macro and setting prompt = No.

Upvotes: 1

Views: 582

Answers (1)

June7
June7

Reputation: 21370

Using VBA instead of embedded macro solved your issue but consider that code can be simplified to:

CurrentDb.QueryDefs("MyQuery").SQL = strNewSQL
Me.mySubForm.SourceObject = "Query.MyQuery"

Upvotes: 1

Related Questions