B
bbxrider
in the example following here, it seems to be invoking the 'yourQuery'
but the sql code is doing that same thing only based on an index
lookup. so........
why is 'yourQuery' being invoked, why not open the table involved
up front and then run the sql?
i was trying to invoke a more complicated query that requires a user input
key to determine which data to look up and how to pass that key to the query
from a form
example:
getting some data based on a user input keyword and eventually displaying it
involved using a predefined query
Select field1, field2, field3 From yourTable
and it's called yourQuery
Now let's say the controls on your form are called:
txtField and txtKeyword
Now something like this code goes in the click event of your cmd button:
**air code**
Dim db As Database
Dim qdf As QueryDef
Dim strSql As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("yourQuery")
strSql = "Select field1, field2, field3 From yourTable " & _
"Where " & Me.txtField & " Like '*" & _
Me.txtKeyword & "*'"
'you might want to view the above to make sure
'it's syntax is correct
MsgBox strSql
qdf.SQL = strSql
'now the query that your report is
'based on has the chosen criteria
Set qdf = Nothing
Set db = Nothing
but the sql code is doing that same thing only based on an index
lookup. so........
why is 'yourQuery' being invoked, why not open the table involved
up front and then run the sql?
i was trying to invoke a more complicated query that requires a user input
key to determine which data to look up and how to pass that key to the query
from a form
example:
getting some data based on a user input keyword and eventually displaying it
involved using a predefined query
Select field1, field2, field3 From yourTable
and it's called yourQuery
Now let's say the controls on your form are called:
txtField and txtKeyword
Now something like this code goes in the click event of your cmd button:
**air code**
Dim db As Database
Dim qdf As QueryDef
Dim strSql As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("yourQuery")
strSql = "Select field1, field2, field3 From yourTable " & _
"Where " & Me.txtField & " Like '*" & _
Me.txtKeyword & "*'"
'you might want to view the above to make sure
'it's syntax is correct
MsgBox strSql
qdf.SQL = strSql
'now the query that your report is
'based on has the chosen criteria
Set qdf = Nothing
Set db = Nothing