Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping thru forms container - object invalid message

Status
Not open for further replies.

CindyK

Technical User
Jan 29, 2001
173
US
I'm trying to use the following code to loop through the forms in an open database, exporting them to another file:
Dim dbs As Database, ctr As Container, doc As Document
Dim strPath As String

Set dbs = CurrentDb
Set ctr = dbs.Containers!Forms
strPath = Forms![frmUpdate]![strFilePath]
For Each doc In ctr.Documents

DoCmd.TransferDatabase acExport, "Microsoft Access", strPath, acForm, doc.Name, doc.Name, False
Next doc
Set dbs = Nothing

The strPath is created by the user on a form before the procedure is run, and it gives me a path that works fine. The code exports the FIRST form, and then returns "object invalid or no longer set".

I gave up last night, thinking I would just do these individually... but even if I list EACH form separately in a line of code using DoCmd.TransferDatabase I still get the same error - once again doing just the first form. Whic makes me think my problem isn't in looping thru the containers - but that somehow my database is losing it's path name??? LOL - as I type through this, I'm beginning to think THAT somewhere along the way I'm losing the path of the mdb that I'm starting with, but am not sure how to fix it. Any thoughts, suggestions?

Thanks in advance.

Cindy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top