[AccessD] Taking Controls from another MDB

MartyConnelly martyconnelly at shaw.ca
Mon Jan 5 14:06:24 CST 2004


Try using TransferDatabase or CopyObject
To get all the names of reports in order to transfer; try mucking about 
with the following code


'OpenDatabase Method Example
'This example uses the OpenDatabase method to open one Microsoft Jet 
database

Sub OpenDatabaseX()

    Dim wrkJet As Workspace
    Dim dbsNorthwind As Database
    Dim dbsPubs As Database
    Dim dbsPubs2 As Database
    Dim dbsLoop As Database
    Dim prpLoop As Property

    ' Create Microsoft Jet Workspace object.
    Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

    ' Open Database object from saved Microsoft Jet database
    ' for exclusive use.
    MsgBox "Opening Northwind..."
    Set dbsNorthwind = wrkJet.OpenDatabase("C:\Program Files\Microsoft 
Office\Office\Samples\Northwind.mdb", _
        True)

    ' Enumerate the Databases collection.
    For Each dbsLoop In wrkJet.Databases
        Debug.Print "Database properties for " & _
            dbsLoop.Name & ":"

        On Error Resume Next
        ' Enumerate the Properties collection of each Database
        ' object.
        For Each prpLoop In dbsLoop.Properties
            If prpLoop.Name = "Connection" Then
                ' Property actually returns a Connection object.

                Debug.Print "    Connection[.Name] = " & _
                    dbsLoop.Connection.Name
            Else
                Debug.Print "    " & prpLoop.Name & " = " & _
                    prpLoop
            End If
        Next prpLoop
        On Error GoTo 0

    Next dbsLoop
'Container Property Example

'This example displays the Container property for a variety of Document 
objects.

' Put report names in a array, can't have two copies of database open when
'using transferdatabase although I suppose you could use copyobject

    Dim dbsNorthwindA As Database
    Dim ctrLoop As Container
    Dim arrReports(30) As String
 
    Set dbsNorthwindA = OpenDatabase("C:\Program Files\Microsoft 
Office\Office\Samples\Northwind.mdb", , ReadOnly)

    ' Display the container name for the first Document
    ' object in each Container object's Documents collection.
    For Each ctrLoop In dbsNorthwindA.Containers
        Debug.Print "Document: " & ctrLoop.Documents(0).Name
        Debug.Print "    Container = " & ctrLoop.Documents(0).Container

    Next ctrLoop
    Dim i As Long
    Dim strReportName As String
    Dim lNoOfReports As Long
    For i = 0 To dbsNorthwind.Containers("Reports").Documents.Count - 1
    '   DoCmd.CopyObject "Insecure.mdb", Tmp, A_REPORT, Tmp
    strReportName = dbsNorthwind.Containers("Reports").Documents(i).Name
    arrReports(i) = strReportName
 
    Debug.Print dbsNorthwind.Containers("Reports").Documents(i).Name
    Next i
   
    lNoOfReports = dbsNorthwind.Containers("Reports").Documents.Count - 1
    'close up database
     dbsNorthwind.Close
       dbsNorthwindA.Close
       wrkJet.Close
     Set dbsNorthwind = Nothing
     Set dbsNorthwindA = Nothing
     Set wrkJet = Nothing
    
  'after closing import the reports
     For i = 0 To lNoOfReports
      DoCmd.TransferDatabase acImport, "Microsoft Access", _
        "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
         acReport, arrReports(i), arrReports(i)
    Next i
  
End Sub

MastercafeCTV wrote:

>Hi group we are trying to take all reports from another MDB, we use the next
>code to see our Reports/Tables/Forms, but how to change
>Application.CurrentProject for c:\MyApp\Sample.MDB??
>
>Function CtlLista(TIPO As String)
>On Error GoTo ctlerror
>    Dim obj As AccessObject, dbs As Object
>    Set dbs = Application.CurrentProject
>    Dim I As Integer
>    Dim frm As Form
>    Dim valores As String
>    valores = ""
>    Select Case TIPO
>    Case "F"
>        For Each obj In dbs.AllForms
>            If valores = "" Then
>                valores = valores & obj.Name
>                Else
>                valores = valores & ";" & obj.Name
>            End If
>        Next obj
>   
>    Case "R"
>        For Each obj In dbs.AllReports
>            If valores = "" Then
>                valores = valores & obj.Name
>                Else
>                valores = valores & ";" & obj.Name
>            End If
>        Next obj
>    Case "T"
>        For Each obj In dbs.AllTables
>            If valores = "" Then
>                valores = valores & obj.Name
>                Else
>                valores = valores & ";" & obj.Name
>            End If
>        Next obj
>Etc...........
>
>
>Thanks
>
>Juan Menendez
>
>
>===========================================
>MASTERCAFE SL - NIF B-82.617.614
>www.mastercafe.com
>Deleg. Asturias 
>Tel 985.88.49.44 / 627.531.764
>Fax 627.500.205
>info at mastercafe.com
>juan at mastercafe.com
>Deleg. Madrid
>Tel 627.474.285
>cecilia at mastercafe.com
>===========================================
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of MastercafeCTV
>Sent: lunes, 05 de enero de 2004 7:09
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] Mac address
>
>
>We check this function and can't obtain any serial from the mainboard. The
>AXP check ok for compiling but return only " ," (two character)
>
>Do you know why??
>
>We use the serial HDD control to check the computer, and with this code
>
>Set fs = CreateObject("Scripting.filesystemobject")
>Set d = fs.getdrive(fs.getdrivename(fs.getabsolutepathname("C:")))
>HDD = d.SerialNumber
>
>The lenght can be 6 or more characters
>
>Juan Menendez
>Mastercafe
>
>===========================================
>MASTERCAFE SL - NIF B-82.617.614
>www.mastercafe.com
>Deleg. Asturias 
>Tel 985.88.49.44 / 627.531.764
>Fax 627.500.205
>info at mastercafe.com
>juan at mastercafe.com
>Deleg. Madrid
>Tel 627.474.285
>cecilia at mastercafe.com ===========================================
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
>Sent: lunes, 05 de enero de 2004 1:40
>To: Access Developers discussion and problem solving
>Subject: RE: [AccessD] Mac address
>
>
>On 4 Jan 2004 at 17:43, John Bartow wrote:
>
>  
>
>>I was just wondering why the Main Circuit Board Serial Number isn't
>>used for this. It would seem to me that this would be about the most 
>>stable unique ID number in a PC. I have no idea how you would read 
>>this number but it always shows up in my hardware asset inventories.
>>
>>Any comments?
>>    
>>
>
>Public Function MBSerialNumber() As String
>
>'RETRIEVES SERIAL NUMBER OF MOTHERBOARD
>'IF THERE IS MORE THAN ONE MOTHERBOARD, THE SERIAL
>'NUMBERS WILL BE DELIMITED BY COMMAS
>
>'YOU MUST HAVE WMI INSTALLED AND A REFERENCE TO
>'Microsoft WMI Scripting Library IS REQUIRED
>
>Dim objs As Object
>
>Dim obj As Object
>Dim WMI As Object
>Dim sAns As String
>
>
>Set WMI = GetObject("WinMgmts:")
>Set objs = WMI.InstancesOf("Win32_BaseBoard")
>For Each obj In objs
>  sAns = sAns & obj.SerialNumber
> If sAns < objs.Count Then sAns = sAns & ","
>Next
>MBSerialNumber = sAns
>End Function
> 
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada





More information about the AccessD mailing list