Hello. I am trying to set the recordset of a form on open using an ado recordset, and I get Runtime Error 2455 - You entered an expression that has an invalid reference to the property Recordset. Below is the code I am using to get the recordset for the form (I have omitted my SQL statement, as it is very long and will take up alot of the page; if you need to see it, let me know and I will post it):
I do not get any errors on the SQL statement, and the "Set Forms("RMA Base Form").Recordset = adRMARS" is the highlighted line in the error. I have used this method before for other forms in my DB, but never for one this large. Also, this form has a couple of subforms on it, could they be the cause? Any help you can provide would be greatly appreciated! Thanks in advance!
Code:
Dim adRMAConn As ADODB.Connection
Dim adRMARS As ADODB.Recordset
Dim RMABaseSQL, srchRMA, srchSN As String
Set adRMAConn = New ADODB.Connection
adRMAConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Nick DeMayo;" & _
"Data Source=T:\Database Project\Customer Support Tables.mdb;" & _
"Mode=ReadWrite|Share Deny None;Persist Security Info=False;" & _
"Jet OLEDB:System database=t:\Database Project\Secured.mdw", "Nick DeMayo", "Nic"
'build the where statement
If Not (IsNull(Forms!frmRMAProcess!txtRMANumber)) Then
srchRMA = RMABaseSQL & " WHERE ((([Work orders].[Closed Date]) Is Null) AND (([Work orders].[RMA Number])=" & Forms!frmRMAProcess!txtRMANumber & "));"
End If
Set adRMARS = New ADODB.Recordset
adRMARS.CursorLocation = adUseClient
adRMARS.Open srchRMA, adRMAConn, adOpenDynamic, adLockOptimistic
Set Forms("RMA Base Form").Recordset = adRMARS
I do not get any errors on the SQL statement, and the "Set Forms("RMA Base Form").Recordset = adRMARS" is the highlighted line in the error. I have used this method before for other forms in my DB, but never for one this large. Also, this form has a couple of subforms on it, could they be the cause? Any help you can provide would be greatly appreciated! Thanks in advance!