If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
VB Code - Query
I have VB code for a query, but I don't know how to turn it into an actual
query. Any advice? Thanks! Here's the basic code (from http://www.microsoft.com/office/comm...b&sloc=en-us): Dim str AS string str= " SELECT " if check1 then str=str & " field1," if check2 then str = str & " field2," .... ' remove the extra coma ( I assume at least ONE field will be selected) str=Left(str, len(str)-1) 'complete the statement str= str & " FROM tableName ... " 'use the string a record source (form/report) or row source (combo box, list box) |
#2
|
|||
|
|||
VB Code - Query
On Jul 14, 10:43*am, Rus925 wrote:
I have VB code for a query, but I don't know how to turn it into an actual query. *Any advice? *Thanks! * ``` Create a querydef object, (make sure it has a name), assign the .SQL property of the object to your SQL statement/function that returns the SQL Statement, and then append it to the querydefs collection. Okay, now tell WHY you need this? Are you building a filter on the fly for your report? There's an answer for that at Access Web. www.mvps.org/access Search for it. Do you intend to just build a query where you can modify the SQL on the fly? (Running out of ideas...) |
#3
|
|||
|
|||
VB Code - Query
Thanks! Exactly: I am using VB to dynamically generate SQL code based on the
user's input in a form (which will also ask for the parameters of the query). Basically, I want the user to quickly be able to choose which fields he/she wants visible in the report and by which field he/she wants to sort from the form, along with what he/she wants to search for. How do I create a querydef object? All I have right now is a module with the code. " wrote: On Jul 14, 10:43 am, Rus925 wrote: I have VB code for a query, but I don't know how to turn it into an actual query. Any advice? Thanks! ``` Create a querydef object, (make sure it has a name), assign the .SQL property of the object to your SQL statement/function that returns the SQL Statement, and then append it to the querydefs collection. Okay, now tell WHY you need this? Are you building a filter on the fly for your report? There's an answer for that at Access Web. www.mvps.org/access Search for it. Do you intend to just build a query where you can modify the SQL on the fly? (Running out of ideas...) |
#4
|
|||
|
|||
VB Code - Query
Dim qdfNew As DAO.QueryDef
Dim strSQL As String strSQL = "SELECT ...." Set qdfNew = CurrentDb.CreateQueryDef("QueryName", strSQL) -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Rus925" wrote in message ... Thanks! Exactly: I am using VB to dynamically generate SQL code based on the user's input in a form (which will also ask for the parameters of the query). Basically, I want the user to quickly be able to choose which fields he/she wants visible in the report and by which field he/she wants to sort from the form, along with what he/she wants to search for. How do I create a querydef object? All I have right now is a module with the code. " wrote: On Jul 14, 10:43 am, Rus925 wrote: I have VB code for a query, but I don't know how to turn it into an actual query. Any advice? Thanks! ``` Create a querydef object, (make sure it has a name), assign the .SQL property of the object to your SQL statement/function that returns the SQL Statement, and then append it to the querydefs collection. Okay, now tell WHY you need this? Are you building a filter on the fly for your report? There's an answer for that at Access Web. www.mvps.org/access Search for it. Do you intend to just build a query where you can modify the SQL on the fly? (Running out of ideas...) |
Thread Tools | |
Display Modes | |
|
|