Run macro till EOF

G

Guest

I have creaded a command button to run the following to export my reports and
save them each with a name in one of the fields. It works but it comes up
with an error at the end because it tries to go to the next record and one
doesn't exist. I need it to either stop at the last record or stop when the
field is blank.

DoCmd.RunCommand acCmdRecordsGoToFirst
DoCmd.RunMacro "Macro4", 100

The following is the setup of Macro4:
OpenReport
Report name: Inventory
View: Print Preview
Filter Name:
Where Condidtion: [ItemID]=[Forms]![Reels]![ItemID]
Window Mode: Normal
OutputTo
Object Type: Report
Object Name: Inventory
Output Format: HTML
Ouput File: ="g:\web\test\" & [Reports]![Inventory]![ItemID] & ".html"
Auto Start: No
Template File:
Encoding: Unicode (UTF-8)
Close
Object Type: Report
Object name: Inventory
Save: Prompt
RunCommand
Command: RecordsGoToNext
 
S

Steve Schapel

Raven,

Where does the 100 come from? Can you try the equivalent of this...

Dim NumberOfRecords As Integer
NumberOfRecords = DCount("*","QueryThatYourFormIsBasedOn")
DoCmd.RunMacro "Macro4", NumberOfRecords
 

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