1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Access VBA Script assistance

Discussion in 'Business Applications' started by jimr381, Oct 16, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. jimr381

    jimr381 Thread Starter

    Joined:
    Jul 20, 2007
    Messages:
    4,189
    First Name:
    Jim
    I tried researching this to no avail. I can get this to work when I hard code in the exact file location but I keep getting an message saying that it cannot open the file when I run this code. I am placing the Word doc in the same location as the access database and wanted to pull in the active files current folder, not the current directory which is the last accessed or default directory.


    Code:
    Private Sub cmdMOAMailMerge_Click()
    On Error GoTo Err_cmdMOAMailMerge_Click
    
        Dim stDocName As String
        DoCmd.SetWarnings False
        stDocName = "qryMOAMailMerge"
        
        DoCmd.OpenQuery stDocName, acNormal, acEdit
            
        straddress = CurrentProject.Path & "PreMOAMailMerge.doc"
        
        Application.FollowHyperlink straddress, , True
        GetUserAddress = True
    
        DoCmd.SetWarnings True
        
    Exit_cmdMOAMailMerge_Click:
        Exit Sub
    
    Err_cmdMOAMailMerge_Click:
        msgbox Err.Description
        Resume Exit_cmdMOAMailMerge_Click
        
    End Sub
    
     
  2. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    Jim, this works for me
    Dim db As CurrentProject
    DoCmd.SetWarnings False
    MsgBox CurrentProject.Path
    straddress = CurrentProject.Path & "\Copy of buys.xls"

    Application.FollowHyperlink straddress, , True

    The message box just shows you where it is looking.
     
  3. Gregor1234

    Gregor1234

    Joined:
    Jun 3, 2004
    Messages:
    237
    I believe you're just missing the slash ("\") cahracter between
    CurrentProject.Path and "PreMOAMailMerge.doc"

    Try

    straddress = CurrentProject.Path & "\PreMOAMailMerge.doc"
     
  4. jimr381

    jimr381 Thread Starter

    Joined:
    Jul 20, 2007
    Messages:
    4,189
    First Name:
    Jim
    Ok thanks. I tried parsing it but knew I was missing something ;)

    It worked I should have looked for that. I tried passing the string into a msgbox to see what it looked like and it was having issues with displaying it. ;)
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/759756

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice