[AccessD] OpenRecordset Error

David Emerson newsgrps at dalyn.co.nz
Fri Dec 9 04:07:28 CST 2011


It is getting late.  Can anyone see why I am getting error 91 Object 
variable or With block variable not set) when the "Set rst2" line is 
run?  I have checked the value of strSQL and it looks ok.  I have put 
the sql into a query and it returns the expected result.  Could it be 
because OpenRecordset doesn't like group by queries?

     Dim db As DAO.Database, rst2 As DAO.Recordset, strSQL As String

     Set db = CurrentDb()

     strSQL = "SELECT Sum(UnitAmt) AS TotalAmt, 
tblTenantInvoiceMeter.TenantInvoiceIDNo "
     strSQL = strSQL & "FROM tblTenantInvoiceMeter INNER JOIN 
tblTenantInvoiceMeterTran ON 
tblTenantInvoiceMeter.TenantInvoiceMeterID = 
tblTenantInvoiceMeterTran.TenantInvoiceMeterIDNo "
     strSQL = strSQL & "GROUP BY 
tblTenantInvoiceMeter.TenantInvoiceIDNo HAVING 
tblTenantInvoiceMeter.TenantInvoiceIDNo = 9"
     Set rst2 = db.OpenRecordset(strSQL)

Regards

David Emerson
Dalyn Software Ltd
Wellington, New Zealand 




More information about the AccessD mailing list