David Emerson
newsgrps at dalyn.co.nz
Fri Dec 9 04:22:23 CST 2011
Never mind. I found it - I had closed db in an earlier part of the code between setting it and referring to rst2. At 9/12/2011, David Emerson wrote: >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 >-- >AccessD mailing list >AccessD at databaseadvisors.com >http://databaseadvisors.com/mailman/listinfo/accessd >Website: http://www.databaseadvisors.com