bhamilton42
Registered User.
- Local time
- Today, 12:39
- Joined
- Jul 30, 2012
- Messages
- 16
Hello all
I was just curious, what's the general opinion on coding standards/efficiency when it comes to executing an SQL query from VBA?
Basically I have a subform datasheet, and the record source is going to be set as the result of a recordset populated from an SQL query. The user enters parameters and the query runs with these parameters, populating a recordset object and then that recordset is used at the record source for the subform.
So, when doing this, I could go to create and make a query and put in [] for the parameters, and then in my code i would use a query def and fill in the parameters and then use doCmd.RunSQL(name of my query, dbOpenDynaset) or, I could just save the query as a string variable in my VBA code, and then just use DoCmd.RunSQL(SQL,dbOpenDynaset)
It's not a tiny query, it's the amalgamation of 4 tables from the database (summation report for the higher ups) and there are 20 requested fields. But it's not the biggest i've run by far. So what might be he best way to have that? saved query or VBA string? what do coding standards say and what runs more efficiently?
I was just curious, what's the general opinion on coding standards/efficiency when it comes to executing an SQL query from VBA?
Basically I have a subform datasheet, and the record source is going to be set as the result of a recordset populated from an SQL query. The user enters parameters and the query runs with these parameters, populating a recordset object and then that recordset is used at the record source for the subform.
So, when doing this, I could go to create and make a query and put in [] for the parameters, and then in my code i would use a query def and fill in the parameters and then use doCmd.RunSQL(name of my query, dbOpenDynaset) or, I could just save the query as a string variable in my VBA code, and then just use DoCmd.RunSQL(SQL,dbOpenDynaset)
It's not a tiny query, it's the amalgamation of 4 tables from the database (summation report for the higher ups) and there are 20 requested fields. But it's not the biggest i've run by far. So what might be he best way to have that? saved query or VBA string? what do coding standards say and what runs more efficiently?