Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2007

Tip: Looking for answers? Try searching our database.

Object invalid or no longer set on CopyObject method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tig - 18 Jan 2007 20:52 GMT
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
Stefan Hoffmann - 19 Jan 2007 10:33 GMT
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 <--
tig - 19 Jan 2007 16:03 GMT
> hi,
>
[quoted text clipped - 24 lines]
> 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.
Stefan Hoffmann - 22 Jan 2007 10:45 GMT
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 <--
tig - 22 Jan 2007 23:02 GMT
> hi,
>
[quoted text clipped - 4 lines]
> mfG
> --> stefan <--

Run-time error '3420' Object invalid or no longer set.  Thanks again
for taking a look.
Stefan Hoffmann - 23 Jan 2007 11:20 GMT
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 <--
tig - 24 Jan 2007 16:40 GMT
On Jan 23, 5:20 am, Stefan Hoffmann <stefan.hoffm...@explido.de>
wrote:
> hi,
>
[quoted text clipped - 3 lines]
> 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?
Stefan Hoffmann - 24 Jan 2007 16:50 GMT
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?
> 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 <--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.