I'm trying to change the recordset of a subform to display the query result
So I have a string query :
sQueryCurrencyRate = "SELECT * FROM Table.Mytable WHERE As_Of_Date =" & Format(dateField.value, "M/d/yyyy")
sQueryCurrencyUsDollar = "SELECT * FROM Table.Mytable WHERE As_Of_Date =" & Format(dateField.value, "M/d/yyyy")
So when I write this , the subform display a result without error :
Me.subformName.Form.RecordsourceSourceObject = "Table.tableName"
but When I try all of the below I always receive an error :
Forms!formName.subformName.Form.RecordSource= sQueryCurrencyRate
I have also tried :
Me.subFormName.Form.RecordsourceSourceObject= sQueryCurrencyRate
Also ,
Me.subFormName.RecordsourceSourceObject= sQueryCurrencyRate
No matter what I do , I always end up having this error message :
the expression you have entered refers to an object that is closed or doesn't exist
What I'm doing wrong? and how to properly display the query result in the subform recordsource ?
P.S: the sql queries syntax are fine because I have previously tested them with :
Set db = CurrentDb
Set rs = db.OpenRecordset(sQueryCurrencyRate)
and I received no error , so the problem is how to bind the subform result to the query
EDIT:
The way I'm calling the code is like below :
Function detectSelectedQuery(sTypeDonnee As String)
sQueryCurrencyRate = "SELECT * FROM Table.Mytable WHERE As_Of_Date = ' " & Format(dateField.value, "M/d/yyyy") &"'"
Me![Child8].Form.RecordSource = sQueryCurrencyRate
end function
then when the combobox is changed I call the function :
Private Sub Combo_descriptionQueries_Change()
detectSelectedQuery (Combo_descriptionQueries.Value)
End Sub
RecordSetObjectpart is wrong, he intends to setRecordSource, which is a string SQL statement that the form uses (there also is aRecordSetproperty, but that shouldn't be changed unless you want to use an ADO recordset as recordsource) - Erik AWHEREclause like this. Sure it makes it "easy" to get something that works, but it's just plain wrong on so many levels. Same holds true for UserForms and their default instance, for example. Too many things are dumbed-down in VBA, it's just crazy. - Mathieu Guindon