Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Aug 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word/Access (English/Office 2K SP3)

    Hello
    Im looking for a way to open an Access DB application from a control button on a Word Userform.
    I have gotten the application to open (once), but each time after that I get an application error and access closes.
    I need for the user to be able to open the DB and work with it (so the code in word needs to end once the DB is open) and the user will close access when they are done.
    Any suggestions?
    Thank you
    Terry V

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

    Re: Word/Access (English/Office 2K SP3)

    There are several ways to do this:
    - using the Shell function.
    - using the ShellExecute API function (you need to declare this).
    - using FollowHyperlink.
    The latter method may be the easiest:

    ActiveDocument.FollowHyperlink "C:AccessTest.mdb"

  3. #3
    New Lounger
    Join Date
    Aug 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word/Access (English/Office 2K SP3)

    Hans
    Thank you for your reply.
    I tried the followhyperlink, and each time I run it, I get a general protection fault when it attemtps to open the access DB. However, when I choose OK on the error box, Access opens with the file opened. I also noticed that it places an extra Access.exe process in my task manager.

    Im trying to use the GetObject to open my access application, but for some reason, it does not open.
    This is what Im using:

    Public Sub AccessApp()
    On Error Resume Next
    Dim oDB As Object
    Dim pth As String
    Set oDB = Access.Application
    oDB.Visible = True
    pth = ThisDocument.Path & "Purchase Orders.mdb"
    Set oDB = GetObject(pth, Access.Application)

    'ActiveDocument.FollowHyperlink pth
    End Sub

    Any Suggestions?
    Thank you
    Terry V

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

    Re: Word/Access (English/Office 2K SP3)

    Your code will not work for two reasons:
    - There are several syntax errors, but those can be repaired.
    - Much more important: Access will vanish the moment the procedure ends.

    The code

    Public Sub AccessApp()
    Dim pth As String
    pth = ThisDocument.Path & "Purchase Orders.mdb"
    ActiveDocument.FollowHyperlink pth
    End Sub

    should work without problems, if the path is correct. Note that all code involving objects has been removed here. If it crashes, there must be something else wrong.

    Note: putting On Error Resume Next in your code is dangerous. It means that you will never find out where or why your code goes wrong. During development, you should see error messages as they are generated by the applications; later on, you need to install a real error handler that presents the user with a user-friendly error message. On Error Resume Next should only be used in very special circumstances.

Posting Permissions

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