Link to home
Start Free TrialLog in
Avatar of Marilyn Messineo
Marilyn MessineoFlag for United States of America

asked on

Object Variable or With Block Variable not set - Microsoft Access vba

Not sure what I'm doing wrong.  But I'm receiving an error "Object Variable or With Block Variable not set":

Public Function Contracts_CRM_audit()
Dim DB As Dao.Database
Dim strSQL As String
Dim rstContracts As Recordset


Set DB = CurrentDb

Do Until rstContracts.EOF
    strSQL = "SELECT Max([Report Date]), [Contract Reference No], Issue from tbl_contracts_crm_Audit_history GROUP BY Issue"
    Set rstContracts = DB.OpenRecordset(strSQL, dbOpenDynaset)
    strIssue = rstContracts!Issue & "; "
    rstContracts.MoveNext
Loop
    MsgBox strIssue

End Function
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
test this
Public Function Contracts_CRM_audit()
 Dim DB As Dao.Database
 Dim strSQL As String
Dim rstContracts As DAO.Recordset

Set DB = CurrentDb
  strSQL = "SELECT Max([Report Date]), [Contract Reference No], Issue from tbl_contracts_crm_Audit_history GROUP BY Issue"
Set rstContracts = DB.OpenRecordset(strSQL, dbOpenDynaset)

Do Until rstContracts.EOF
    strIssue = strIssue & ";" & rstContracts!Issue & "; "
     rstContracts.MoveNext
 Loop
     MsgBox strIssue

 End Function 

Open in new window

Avatar of Marilyn Messineo

ASKER

Thanks!