Hi All
This is a very basic question but I cant seem to get around it. I have a query that I am using multiple times so I have saved that query in a string variable. Now that query is using ID in the where clause which I need to update dynamically so I made an Int variable and concatenated that in my string variable. Problem I guess is the preceding order of statements:
I define the string variable (which is the query)
I define the ID variable (integer)
Execute the string variable as query
Now the string query does not update the ID int variable after it has been defined which is problematic as I cant re-use it without redefining the string query again, Only work around I can think of is create a func which updates the ID int in the string query and returns the updated string variable.
Any Ideas? Thanks!
This is a very basic question but I cant seem to get around it. I have a query that I am using multiple times so I have saved that query in a string variable. Now that query is using ID in the where clause which I need to update dynamically so I made an Int variable and concatenated that in my string variable. Problem I guess is the preceding order of statements:
I define the string variable (which is the query)
I define the ID variable (integer)
Execute the string variable as query
Now the string query does not update the ID int variable after it has been defined which is problematic as I cant re-use it without redefining the string query again, Only work around I can think of is create a func which updates the ID int in the string query and returns the updated string variable.
Any Ideas? Thanks!
Code:
Sub QueryDoesntUpdateWhereClause()
dim str as string
dim i as integar
Dim RS as Recordset
i = 5
str = "Select * from Customers where Customer.ID = " & i
set RS=Currentdb.OpenRecordSet(str)
'Do Something with the RecordSet
set RS = Nothing
i = 10
set RS=Currentdb.OpenRecordSet(str) ' This will still show recordset based on i=5!!!
'Do Something
set RS = Nothing
End Sub