Hi,
I want to create a report that will list out a supplier's information based on a supplier's ID. In other words, the report's Recordsource should change according to supplier ID (I think it should be a SQL thing). However, everytime I ran the codes (listsed below), the error message popped up. It says run-tim error '91' Object variable or with block variable not set. I looked Help, no good!
I have two questions:
1. How can I fix the run-time error?
2. Is it the right way to set a report's Recordsouce under Report_Activate()? Is there a better way to do it?
Thanks
Cowper
Here is my code:
Private Sub Report_Activate()
Dim cnn As ADODB.Connection
Dim rsSupplier As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
strSQL = "Select * from tblSupplier where Supplier_ID = '" & Me.txtSupplierID & "';"
rsSupplier.Open strSQL, cnn, adOpenStatic, adLockOptimistic
Me.Report.RecordSource = strSQL
rsSupplier.Close
cnn.Close
End Sub
I want to create a report that will list out a supplier's information based on a supplier's ID. In other words, the report's Recordsource should change according to supplier ID (I think it should be a SQL thing). However, everytime I ran the codes (listsed below), the error message popped up. It says run-tim error '91' Object variable or with block variable not set. I looked Help, no good!
I have two questions:
1. How can I fix the run-time error?
2. Is it the right way to set a report's Recordsouce under Report_Activate()? Is there a better way to do it?
Thanks
Cowper
Here is my code:
Private Sub Report_Activate()
Dim cnn As ADODB.Connection
Dim rsSupplier As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
strSQL = "Select * from tblSupplier where Supplier_ID = '" & Me.txtSupplierID & "';"
rsSupplier.Open strSQL, cnn, adOpenStatic, adLockOptimistic
Me.Report.RecordSource = strSQL
rsSupplier.Close
cnn.Close
End Sub