MS Access Import Forms from another mdb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mac Campbell
    New Member
    • Apr 2007
    • 8

    MS Access Import Forms from another mdb

    Is there a simple way to import all forms from another mdb into the currently open mdb? I have trouble getting the current code to "see" a "forms" object in the external mdb.
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    did u try File/Get External Data/Import ?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      For all forms (especially when there are many) the Import method is best. For an individual form, it is possible to use simply Copy/Paste as long as both databases are open.

      Comment

      • Mac Campbell
        New Member
        • Apr 2007
        • 8

        #4
        Originally posted by pks00
        did u try File/Get External Data/Import ?
        That works great but I would like to be able to do this using VBA code.
        In trying this, I have problems setting up the foreign "Forms" object to cycle through. Any Ideas?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          Forms is an attribute of the Application object and is NOT what contains the objects to be imported.
          The Forms collection contains only open forms in the currently open database.

          Comment

          • Mac Campbell
            New Member
            • Apr 2007
            • 8

            #6
            Originally posted by NeoPa
            Forms is an attribute of the Application object and is NOT what contains the objects to be imported.
            The Forms collection contains only open forms in the currently open database.
            I would like to do this in VBA because there seems to be a hole in my understanding of the "Forms" identity. If I View the objects, I can see what appears to be a "Forms" object but I could not create or "cast" the Application.Cur rentProject.All forms (object/container) into a Forms object. I seem to have a blind spot here. Is there a good source where I might get an understanding of this.

            Comment

            • joeldb
              New Member
              • May 2007
              • 2

              #7
              Hi

              I am trying to do exactly the same thing. Have you found a way yet?


              Originally posted by Mac Campbell
              I would like to do this in VBA because there seems to be a hole in my understanding of the "Forms" identity. If I View the objects, I can see what appears to be a "Forms" object but I could not create or "cast" the Application.Cur rentProject.All forms (object/container) into a Forms object. I seem to have a blind spot here. Is there a good source where I might get an understanding of this.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Originally posted by Mac Campbell
                I would like to do this in VBA because there seems to be a hole in my understanding of the "Forms" identity. If I View the objects, I can see what appears to be a "Forms" object but I could not create or "cast" the Application.Cur rentProject.All forms (object/container) into a Forms object. I seem to have a blind spot here. Is there a good source where I might get an understanding of this.
                There probably is, but I'm not that good on external references.
                Application.Cur rentProject.All Forms is a Collection object. The object 'contains' form objects but is not, itself, a Form object. Does that throw any light on the problem?

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  Originally posted by joeldb
                  Hi

                  I am trying to do exactly the same thing. Have you found a way yet?
                  Joel,
                  You can see the same as we can what's in here.
                  Your choices are to :
                  1. Follow this thread (you're already subscribed now).
                    You can contribute too if that will help.
                  2. Create a new thread of your own with a well phrased question.

                  Please don't though, divert the course of this thread for your own purposes (Don't worry - you haven't done so far) as that can cause confusion and irritation for all concerned.

                  MODERATOR.

                  Comment

                  • joeldb
                    New Member
                    • May 2007
                    • 2

                    #10
                    Hi

                    I've managed to do it like this:

                    Code:
                    Dim appAccess As Access.Application
                    Dim fileNameStr As String
                    Dim frmSearch As Variant
                    
                    ' this is the file you are importing from
                    fileNameStr = "C:\My Documents\Update1.mdb"
                    
                    Set appAccess = New Access.Application
                    appAccess.OpenCurrentDatabase fileNameStr
                    
                    For Each frmSearch In appAccess.CurrentProject.AllForms
                    
                    'transfer each form - use the same name
                    DoCmd.TransferDatabase acImport, "Microsoft Access", fileNameStr, acForm, frmSearch.Name, frmSearch.Name
                    
                    ' for testing
                    Debug.Print frmSearch.Name
                    
                    Next frmSearch
                    
                    appAccess.CloseCurrentDatabase
                    Set appAccess = Nothing


                    Hope this helps

                    Joel


                    Originally posted by joeldb
                    Hi

                    I am trying to do exactly the same thing. Have you found a way yet?
                    Last edited by NeoPa; May 10 '07, 02:43 PM. Reason: Tags

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Originally posted by joeldb
                      Hi

                      I've managed to do it like this:

                      Code:
                      Dim appAccess As Access.Application
                      Dim fileNameStr As String
                      Dim frmSearch As Variant
                      
                      ' this is the file you are importing from
                      fileNameStr = "C:\My Documents\Update1.mdb"
                      
                      Set appAccess = New Access.Application
                      appAccess.OpenCurrentDatabase fileNameStr
                      
                      For Each frmSearch In appAccess.CurrentProject.AllForms
                      
                      'transfer each form - use the same name
                      DoCmd.TransferDatabase acImport, "Microsoft Access", fileNameStr, acForm, frmSearch.Name, frmSearch.Name
                      
                      ' for testing
                      Debug.Print frmSearch.Name
                      
                      Next frmSearch
                      
                      appAccess.CloseCurrentDatabase
                      Set appAccess = Nothing


                      Hope this helps

                      Joel
                      Nice solution Joel :)
                      It uses Application Automation too.
                      We always appreciate when members post answers after finding them, so well done on that score too.

                      BTW Within Access, the object Application would be equivalent (and predefined) for what you set up in appAccess.

                      Comment

                      Working...