Open Recordset in Loop

A

ajbarilla

I am having problems opening a recordset within a loop. Below is my
code and I get a compile error (End if without block if) when I try to
run it. The loop and recordset code work independently but not
togother. The code is to merge several documents based on ones that
are selected in a list box. the code below contains just the begining
of the merge not the entire merging process.


For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
SearchCrit = List0.ItemData(intCurrentRow)
Set rst = db.openrecordset("SELECT * FROM tblDocumentList WHERE
tbldocumentlist.[Document] = '" & SearchCrit & "'")
With rst
docpath = !location
rst.Close
End If

Next intCurrentRow
 
D

Daniel

Code formatting would help you identify the source of your problem.

For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
SearchCrit = List0.ItemData(intCurrentRow)
Set rst = db.openrecordset("SELECT * FROM tblDocumentList WHERE
tbldocumentlist.[Document] = '" & SearchCrit & "'")
With rst
docpath = !location
End With 'This was missing
rst.Close
End If
Next intCurrentRow 'This was missing

Daniel
 
D

Douglas J. Steele

You're missing the End With to close the With rst line.

Realistically, there's no advantage to using With: I'd remove the

With rst

line, and change

docpath = !location

to

docpath = rst!location
 
A

aaron.kempf

good stuff

for the record, you fucking retard

DAO hasn't been included with 70% of the recent Office releases.. and
it hasn't been present on Windows since Windows 2000, right?

-Aaron
 

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