简体   繁体   中英

VBA SQL statement run time error 91

I keep getting run time error 91 object variable or with block variable not set. I have rs and strQuery as global variables, this is just a snipet of code not the entire thing. Can someone help me out with troubleshooting this?

Dim strQuery
Global db As DAO.Database
Global rs As DAO.Recordset 
strQuery = "SELECT courses.[CourseCode] as CODE, " & _
           "courses.[CourseName] as NAME " & _
           "FROM courses;"
Set rs = db.OpenRecordset(strQuery) 'error here 

db is not pointing to anything - you need to assign that to something.

Eg

Set db = CurrentDb()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM