Results 1 to 6 of 6
  1. #1
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17

    How and were can I put an error message in the right place?

    On a form I have created a command button that opens a Word file called "Instructions for Inventory Program". I've discovered that, if the file has been moved, deleted, or renamed, Access gives the user an unfriendly message and leaves Word open. I want to replace the message Access displays with a more friendly and understandable message of my own. I've tried everything I can think of with no luck. For now, I've placed a message at the beginning of the procedure, but they have to see this every time. I only want a message to be shown if the file is not found.

    I'd really appreciate any suggestions as to where and how I can get Access to display my message at the appropriate time in the procedure, and only if the file is not found.

    Here is the code I'm using right now:

    Private Sub View_manual_button_Click()



    MsgBox "If the Instruction manual can not be found you will receive an error message." & vbCrLf & vbCrLf & "IMPORTANT: If the file can not be found you must immediately close Word to prevent futher error messages."

    On Error GoTo Err_View_manual_button_Click

    Dim oApp As Object
    Set oApp = CreateObject("Word.Application")
    oApp.Visible = True


    Exit_View_manual_button_Click:


    Exit Sub

    Err_View_manual_button_Click:

    MsgBox Err.Number

    Resume Exit_View_manual_button_Click


    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Presumably there's more to it, but you can use the Len() and Dir() functions to test for the existence of the file to be opened before proceeding.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17
    Sinced I created the command button from the controls at the bottom of the form in design view, Access created the code for me. The code I posted is all I can find. It doesn't even include the file name. On the properties for the commandf button, the hyperlink line is "Instructions%20for%20CAFP%20Inventory%20Program.d oc"

    I don't see anywhere to test for the existence of the file.

    Obviously I'm very new to this and don't know much at all about coding.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Maybe use error handler code to trap the particular error. Need to know the error number, make note of it the next time you run the code then try building error handler to trap. However, I am not sure it will be trapped before or after Word is already open.

    Review: http://allenbrowne.com/ser-23a.html

    Another approach is to use FollowHyperlink in VBA instead of the Hyperlink property of textbox.

    Also might be of interest http://allenbrowne.com/func-GoHyperlink.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jnrussell is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Posts
    17
    I don't see an error number. All I get is the message "Unable to to open Instructions%20for%20CAFP%20Inventory%20Program.do c. Cannot open the specified file.". And I can't find that message in any of the online lists of error codes. I'll check out your links and hope there will be some help there.

  6. #6
    trevor40's Avatar
    trevor40 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    407
    all this does is open word and show it, unless you have the file and path provided elseware

    Dim oApp As Object
    Set oApp = CreateObject("Word.Application")
    oApp.Visible = True

    you then need to tell word what file to use,
    you need to provide the full path and file name for word to find the file

    sample found on web

    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    Set wordApp = New Word.Application
    With wordApp
    .Visible = True
    Set wordDoc = .Documents.Open("C:\Word\Doc1.doc", , False)
    End With

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  2. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  3. Error message 'Error in Loading DLL'
    By rahayes in forum Programming
    Replies: 2
    Last Post: 09-22-2012, 05:17 AM
  4. Replies: 2
    Last Post: 06-23-2012, 11:59 PM
  5. Getting #Error Message
    By cec in forum Programming
    Replies: 6
    Last Post: 04-18-2012, 02:24 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