Object invalid or no longer set on CopyObject method

  • Thread starter Thread starter tig
  • Start date Start date
T

tig

I thought you could use the CopyObject method on anything but modules,
but I continue to get this error when looping though my dbs. I've
tried TransferDatabase and get the same result

Any ideas?

TIA

Here's my code:

Sub copy_forms()

Dim x
Dim dbnames(1 To 9) As String
dbnames(1) = "C:\db1.mdb"
dbnames(2) = "C:\db2.mdb"
dbnames(3) = "C:\db3.mdb"
dbnames(4) = "C:\db4.mdb"
dbnames(5) = "C:\db5.mdb"
dbnames(6) = "C:\db6.mdb"
dbnames(7) = "C:\db7.mdb"
dbnames(8) = "C:\db8.mdb"
dbnames(9) = "C:\db9.mdb"

For Each x In dbnames
DoCmd.CopyObject x, "Main", acForm, "Main"
'DoCmd.TransferDatabase acExport, "Microsoft Access", x, acForm,
"Main", "Main"
Next

Close
MsgBox "Form Copies Complete"

End Sub
 
hi,
Sub copy_forms()

Dim x
Dim dbnames(1 To 9) As String

For Each x In dbnames
You can only enumerate Collections, not arrays.

Use

Dim Index As Long
For Index = LBound(dbnames()) To UBound(dbnames())
Next Index

or

Dim x As Variant
Dim dbnames As Collection
Set dbnames = New Collection
dbnames.Add "nam"
For Each x In dbnames

Despite that, i'm not sure whether x should be declared as Object instead.



mfG
--> stefan <--
 
Stefan said:
hi,

You can only enumerate Collections, not arrays.

Use

Dim Index As Long
For Index = LBound(dbnames()) To UBound(dbnames())
Next Index

or

Dim x As Variant
Dim dbnames As Collection
Set dbnames = New Collection
dbnames.Add "nam"
For Each x In dbnames

Despite that, i'm not sure whether x should be declared as Object instead.



mfG
--> stefan <--

Stefan

Thanks for the suggestion. Unfortunately I got the same error using
either of your suggestions as well. I did test mine out with multiple
macros and that seems to work. Which leads me to believe it's related
to forms.

It doesn't make sense though that Microsoft would note that you use
this method with forms in their help file.

Any new ideas??

Thanks again.
 
hi,
Thanks for the suggestion. Unfortunately I got the same error using
either of your suggestions as well.
What error message and number do you get?


mfG
--> stefan <--
 
Stefan said:
hi,

What error message and number do you get?


mfG
--> stefan <--

Run-time error '3420' Object invalid or no longer set. Thanks again
for taking a look.
 
hi,
Run-time error '3420' Object invalid or no longer set. Thanks again
for taking a look.
There is a single Close in your code. What should be closed?


mfG
--> stefan <--
 
hi,


mfG
--> stefan <--

Hmmm...I think originally I was thinking I needed close each database
after I updated it. It's not in the loop anymore. I should probably
just get rid of that. Do you think that's what my problem is?
 
hi,
Hmmm...I think originally I was thinking I needed close each database
after I updated it. It's not in the loop anymore. I should probably
just get rid of that. Do you think that's what my problem is?
Yup. Close is a method of many objects, but you have call it
Object.Close. In your code there is no Object. part.


mfG
--> stefan <--
 
Back
Top