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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Open db from a form event (Win XP Office 2003)

    Author
    Topic
    #457699

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #1148359

      You can use an instruction like

      OpenCurrentDatabase “C:DatabasesInvoice.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/

      • #1148457

        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?

        • #1148496

          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”, “C:DatabasesInvoice.mdb”, 0, 0, SW_SHOWMAXIMIZED
          Quit
          End Sub

          • #1148529

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

            • #1148532

              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.

            • #1148548

              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.

    Viewing 0 reply threads
    Reply To: Open db from a form event (Win XP Office 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: