Object variable or With block variable not set in simple Query loop

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

wow, been a busy weekend for me, another question...

I am trying to set up a simple loop through a query and I am getting the
famous 'Object variable or With block variable not set' error, it appears to
be the FileName field, any help would be appreciated. There is definitely
data in the query

Dim ID As Integer
Dim FileName As String
Dim SQLStmt As String
Dim rs As Recordset

SQLStmt = "SELECT ID, FileName"
SQLStmt = SQLStmt & " FROM Query1"

Set rs = db.OpenRecordset(SQLStmt)

Do Until rs.EOF = True

OpenAcrobat
PrintPDFDoc2 rs!FileName

rs.MoveNext

Loop
 
V

Van T. Dinh

1. ID and FileName variables are declared but not used?

2. (this may be the error you posted)

Set rs = db.OpenRecordset(SQLStmt)

db does not seem to be set anywhere in the posted code. If you want to use
the Current DB without seeing the ObjectVariable, try:

Set rs = CurrentDb.OpenRecordset(SQLStmt)
 
P

pubdude2003 via AccessMonster.com

man, I must need some sleep, the fix

Dim ID As Integer
Dim FileName As String
Dim SQLStmt As String
Dim rs As DAO.Recordset
Dim db As DAO.Database

Set db = CurrentDb()

SQLStmt = "SELECT ID, FileName"
SQLStmt = SQLStmt & " FROM query1"

Set rs = db.OpenRecordset(SQLStmt)

Do Until rs.EOF = True
OpenAcrobat
PrintPDFDoc2 rs!FileName

rs.MoveNext

Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top