Avatar billede roose Nybegynder
08. august 2003 - 22:47 Der er 12 kommentarer og
1 løsning

Automatisk import af tabeller, formularer mv.

Ved brug af funktionen DoCmd.TransferDatabase acImport kan jeg importere en række tabeller, formularer mv.
Jeg skal dog her kende navnet på det jeg ønsker at importerer.

Hvordan kan jeg importerer alle tabeller, rapporter, formularer, makroer mv. fra "db_update" til "db_old" uden at kende navnene på de enkelte (og uden at kende antallet af objekter der skal importeres)?
Avatar billede terry Ekspert
09. august 2003 - 14:17 #1
hi roose>can you tell me why you need to do this without knowing the object names? If you dont know the names then I assume that you want to import ALL objects and if that is the case then why not just copy the dB?
Avatar billede roose Nybegynder
09. august 2003 - 14:27 #2
hi terry. The original database is very large - the update.mdb will contain new forms, reports etc. If I can copy update.mdb into the original database without overwriting the objects that needs no replacement it would be the easiest - but I actually would like to do it as I descirbed above.

However, I've managed to update the tables using the TableDefs - but there does not exist a "ReportDefs". That gives me trouble....

I need to get the names of the reports (and forms, and modules) in the update.mdb - but how ? In the original db I can use the "AllReports" but it only applies to the CurrentDB - can I change the CurrentDB to the update.mdb, get the names of the objects and then change the CurrentDB back ??
Avatar billede terry Ekspert
09. august 2003 - 14:32 #3
You can use automation to open the other dB and cycle through the objects.
I have recently given an example of automating anothr Access dB. Will just see if I can find it.
Avatar billede terry Ekspert
09. august 2003 - 14:36 #4
Private Sub Command2_Click()
Dim acc As Access.Application

    Set acc = CreateObject("Access.Application")

    acc.OpenCurrentDatabase "C:\test.mdb"

'now you have an Access object named acc
'use it as follows (example)

acc.DoCmd.OpenReport "SomeReport"

End Sub
Avatar billede roose Nybegynder
09. august 2003 - 14:39 #5
The problem is, that I don't know the name of the report - can I use an index ?
Avatar billede terry Ekspert
09. august 2003 - 14:50 #6
I havent tried this but you should be able to use AllReports in the NEW Access object (acc) to get the name of each report.
Or am I missing something?
Avatar billede roose Nybegynder
09. august 2003 - 15:00 #7
I can get the AllReports to do any good.. I've tried the following:

Sub skift()
Dim rpt As Object
Dim acc As Object

    Set acc = CreateObject("Access.Application")


    acc.OpenCurrentDatabase "C:\update.mdb"
   
    For Each rpt In acc.AllReports
           
              MsgBox rpt.Name
       
    Next
   
   
'    acc.DoCmd.OpenReport ("rp1")
'  MsgBox acc.Reports.Item(a).Name
 
'acc.DoCmd.OpenReport "SomeReport"


End Sub
Avatar billede terry Ekspert
09. august 2003 - 15:20 #8
I'll have a play around and get back later.
Avatar billede terry Ekspert
09. august 2003 - 18:54 #9
Private Sub Command0_Click()
Dim acc As Access.Application
Dim rpt As Object
Dim obj As AccessObject, dbs As Object

    Set acc = CreateObject("Access.Application")

    acc.OpenCurrentDatabase "F:\Data\Access Apps\EXAMPLES\DemoImport.mdb"

    Set dbs = acc.Application.CurrentProject
   
    ' Search for open AccessObject objects in AllReports collection.
    For Each obj In dbs.AllReports
            ' Print name of obj.
            Debug.Print obj.Name
    Next obj


End Sub
Avatar billede terry Ekspert
09. august 2003 - 18:58 #10
You should maybe add this after the last line of code

acc.CloseCurrentDatabase
Set acc = Nothing
Avatar billede roose Nybegynder
10. august 2003 - 11:07 #11
Oh my God.... Terry is a genius. Thank you for superb help - it all works just fine now. Brilliant solution !
Avatar billede terry Ekspert
10. august 2003 - 13:43 #12
No I'm no genius jsut lots of experience :o)
Avatar billede terry Ekspert
10. august 2003 - 13:44 #13
og tak
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester