Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open db from a form event (Win XP Office 2003)

    From an event on a form in db1 I need to open db2 and close db1. Can you point me in the right direction, please.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Open db from a form event (Win XP Office 2003)

    You can use an instruction like

    OpenCurrentDatabase "CatabasesInvoice.mdb"

    Please note that opening another database will instantly close the database running the code, so the code will end abruptly at the above instruction - all instructions after that line will not be executed any more/

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open db from a form event (Win XP Office 2003)

    I get an error message "You already have the database open". I put the line of code in the on-click event of an empty form, just to test it. Any ideas?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Open db from a form event (Win XP Office 2003)

    I apologize - I should have known that OpenCurrentDatabase is only intended to be used when automating Access from another application. You can use code like this instead:

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Private Const SW_SHOWMAXIMIZED As Long = 3
    Private Const SW_SHOWNORMAL As Long = 1

    Private Sub Details_Click()
    ShellExecute 0, "Open", "CatabasesInvoice.mdb", 0, 0, SW_SHOWMAXIMIZED
    Quit
    End Sub

  5. #5
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open db from a form event (Win XP Office 2003)

    I am still having troubles. Here is my sample file. Could you please take a look?
    Attached Files Attached Files

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Open db from a form event (Win XP Office 2003)

    What kind of troubles?

    I replaced the path and filename in your code with those of a database on my PC, then switched to form view and clicked the text box. The other database was opened and the database with the code was closed.

  7. #7
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open db from a form event (Win XP Office 2003)

    When I ran the code, the only thing that happened was that the original db closed. I re-did it with 2007 and it worked. I went back to 2003, erased everything, and re-did it, and it worked. Who knows? Anyway, it worked, and once again the Woody's gang has saved a poor programmer. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •