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
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