Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

    Referring to a form in another database

    I am creating text files for forms in another database so that I can check out the VBA code used in the form. This has been working using the following code:
    Code:
        Set app = New Access.Application
        Set app = fGetRefNoAutoexec(FileName)
        Set dbs = app.CurrentDb
    .....
      dbs.Application.SaveAsText x, doc.Name, FileN
    .....
    The trouble with this code is that it opens the database. I found some other code that references another database without opening it:


    Code:
    Set dbs = DBEngine(0).OpenDatabase(FileName)
    But this gives me a compile error: Method or Data Member not found (on the dbs."Application").

    Is there a way to refer to the forms in another database without actually opening it, just pointing to it?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Is there a way to refer to the forms in another database without actually opening it, just pointing to it?
    short answer is no. Forms will only work in the db where they are, so you have to open the db one way or another

    You can make the other db a library to the current db and have a module in the other db with a procedure something like this - basically just calling openform from the library objects
    Code:
    Public Sub OpenLibraryForm(FormName As String, Optional View As AcFormView, Optional FilterName As Variant, Optional WhereCondition As Variant, Optional DataMode As AcFormOpenDataMode, Optional WindowMode As AcWindowMode, Optional OpenArgs As Variant)
    
        DoCmd.openForm FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs
    
       End Sub
    the other code I have is opens the other db in the background

    Code:
    Function OpenRemoteForm(MDBFile As String, FormName As String, Optional ViewMode As Long = acViewNormal)
        Dim appAccess As Access.Application
        
        If Len(Dir(MDBFile)) > 0 Then
            Set appAccess = New Access.Application
            With appAccess
                apiSetForegroundWindow .hWndAccessApp
                apiShowWindow .hWndAccessApp, SW_HIDE
                .OpenCurrentDatabase MDBFile, False
                .DoCmd.openForm FormName, ViewMode
            End With
        End If
    End Function
    note forms to be opened may need to be popup and modal

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Thanks for your reply. I'm not opening the form, not to display it anyway. All I need to do is read the VBA code for which I am using SaveAsText. The trouble with using NEW is that the database takes so long to open whereas my second method above took no time at all, with the added advantage of there being no window. The database I took that from was changing the options and properties of the external database, which is different to going into the objects, I guess.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    if the code is in a form module you'll have to open the form anyway.

    seems to me it would be a lot simpler just to manually copy the code

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    seems to me it would be a lot simpler just to manually copy the code
    ...but not nearly as much fun!

    However, this is not a one-time deal, it will be done for all databases that go thru development.

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I don't think SaveAsText is considered "opening" the form, is it? I have to admit to sometimes copying code without really understanding it.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I have used the following --save a form without opening it.
    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : jsaveForm
    ' Author    : Jack
    ' Created   : 12/1/2009
    ' Purpose   :  To save as Form as a textfile
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '------------------------------------------------------------------------------
    '
    Sub jsaveForm()
          Dim db As DAO.Database
          Dim obj As Object
          Dim a As String
          Dim B As String
    
    10    a = "frmSourceOfBusinessCBX"
    20    B = "c:\users\mellon\documents\frmSourceOfBusinessCBX.txt"
    30       On Error GoTo jsaveForm_Error
    
    40    Set db = CurrentDb
    50    Application.SaveAsText acForm, a, B
    60       On Error GoTo 0
    70       Exit Sub
    
    jsaveForm_Error:
    
    80        MsgBox "Error " & err.number & " (" & err.Description & ") in procedure jsaveForm of Module ADO_Etc"
    
    End Sub

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It's that "Application" that I am trying to get around - that requires the database to be opened.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    have you tried transferdatabase? example here transfers a report

    https://msdn.microsoft.com/en-us/lib.../ff196455.aspx

    still opens the db though

  11. #11
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    And I would still have to save it as text, adding an extra step.

    I was hoping to use the second way of opening the database in my first post and combining that with saving to a text file. I haven't found an answer anywhere so maybe it isn't possible.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    really don't think it is possible without opening the file - same as getting data from excel, word, etc

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Have you seen this?
    http://www.datastrat.com/Code/DocDatabase.txt

    Maybe you could open a different dB in the background (using part of the code from Ajax in Post #2) and export the code....????

  14. #14
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That's where I got my original code from! I will do some more experimenting tomorrow and let you know.

  15. #15
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe this will help:

    In Access help, search for "OpenDatabase". Then open "Workspace.OpenDatabase Method". There is code (at the bottom) for opening multiple databases.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 01-28-2012, 11:05 AM
  2. Referring to another table for a text box
    By hawkins in forum Reports
    Replies: 5
    Last Post: 07-05-2011, 04:14 PM
  3. Replies: 2
    Last Post: 11-26-2010, 04:20 AM
  4. Referring to objects
    By stubbly in forum Programming
    Replies: 1
    Last Post: 10-14-2009, 09:36 AM
  5. Referring to fields in tab controls
    By AndrewAfresh in forum Forms
    Replies: 1
    Last Post: 06-03-2006, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums