Results 1 to 7 of 7
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Combining text string and field values to make one string of text

    Hello,

    I am trying to generate a string in VBA to combine text with the value of textboxes in the form that is open which will eventually become a file path.

    I'm trying the following but keep getting an error message:

    Private Sub Button_Click()
    Dim NameOfFile as String
    NameOfFile = "C:\Users\User1\Documents\" & [Customer Name] & "_" & [Customer ID Number] & ".pdf"
    DoCmd.OutputTo acOutputForm, "Customer Form", acFormatPDF, NameOfFile, False, , , acExportQualityPrint
    End Sub

    The error message that I continue to get is:
    Run-time error '2501':


    The OutputTo action was canceled.

    I'm assuming that there's something slightly off with the syntax.

    Any assistance would be greatly appreciated.

    Thank you!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Add

    Debug.Print NameOfFile

    and use this to see how the path is coming out:

    BaldyWeb-Immediate window
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    it's telling me:

    C:\Users\E63430\Documents\John Smith.pdf

    (I removed the id number, that wasn't 100% necessary yet)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Network permissions can prevent programmatic saving files into user folders.
    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
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    It's my personal computer and I have the ability to save a file if I just name it any other name - it's only having an issue when I'm trying to use a text string, this is mind-boggling

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    User folder is named E63430? There is a user profile for E63430?

    You say a literal text path value works but not the concatenation? What is that path?

    I have encountered issues with copying files into User folders on my laptop even though I am logged on as 'Owner' and supposedly have full administrative privileges. I usually use C:\ root in my code testing.

    I even failed to install a dll even though tried as Owner. Windows 7 has been very frustrating on my laptop.
    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.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    why is the specified "User1" part being replaced with "E63430" and where is the underscore and customer id number

    NameOfFile = "C:\Users\User1\Documents\" & [Customer Name] & "_" & [Customer ID Number] & ".pdf"

    in your immediate window output "C:\Users\E63430\Documents\John Smith.pdf". Check the values of any variables you are using for those parts and see if they're null or empty.

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

Similar Threads

  1. Replies: 16
    Last Post: 11-03-2014, 02:38 PM
  2. Replies: 3
    Last Post: 12-22-2012, 05:33 PM
  3. Replies: 6
    Last Post: 08-10-2012, 02:28 PM
  4. Combining values of 2 columns into one string
    By LAazsx in forum Programming
    Replies: 1
    Last Post: 11-25-2010, 08:36 PM
  5. Extract numbers from text string strored in a field.
    By khabdullah in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 06:55 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