Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77

    Call MakeDir Failing on certain systems

    for some reason there are 2 computers out of 15 that are giving me an Error 75 Path/File not found. When i replace %USERNAME% with their actual username it works.



    UserVenuePath is being pulled from a separate database. the path is c:\Users\%USERNAME%\OneDrive - Caterer\Caterer Name. the reason i am using %USERNAME% is users share computers and their one drive path changes. stepped it through and it fails on the 'Call MakeDir(strFilePath)'. like i said only happening on 2 systems. If i cut and paste the path in windows explorer, c:\Users\%USERNAME%\OneDrive - Caterer\Caterer Name it resolves fine.

    Any help would be appreciated.

    Code:
    Private Sub Command276_Click()DoCmd.RunCommand acCmdSaveRecord
    
    
    Dim UserVenuePath As String
    Dim strFilePath As String
    Dim strReport As String
    
    
    UserVenuePath = DLookup("[FilePath]", "tbl_SystemInfo", "[SystemInfoID] = 1")
    strFilePath = UserVenuePath & "\Contracts\" & Format(Form_frm_Contract.DateofFunction, "MM-DD-yyyy") & "\" & Form_frm_Contract.DayTimeFunction & "\"
    strFileName = Form_frm_Contract.NameonContract & ".pdf"
    
    
    If FolderExists(strFilePath) = False Then
              Call MakeDir(strFilePath)
    Else
              MsgBox "This folder already exists.", vbInformation, "Folder Exists"
    End If
    
    
    'First let's open the report
    strReport = "rpt_Contract"
    DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = [Forms]![frm_Contract]![ContractsID]", acWindowNormal
    
    
    'Now let's save the open report to .PDF
    DoCmd.SelectObject acReport, strReport
    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False, , , acExportQualityPrint
    DoCmd.Close acReport, strReport
    
    
    'Display Message
    MsgBox "New file has created successfully in the new folder!", vbInformation, "VBAF1"
    
    
    End Sub

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You are much better of using a UNC/URL path for one drive locations.

    https://yourfirms-my.sharepoint.com/personal/myfolder...

    This should work from anywhere.

    If not, what is the operating system version on the PC's that don't work?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Hmm,
    I would have thought you would need to use Environ("Username") in VBA
    Not sure VBA would have any idea of system variables without it?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    Windows 10

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by jazzy View Post
    Windows 10
    And does it work on other that are on windows 10?
    What other difference are there between those machines Office versions, mapped drive letters, etc?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    they have windows 10 as well. cant figure it out at all. some work some dont. we are not using mapped drives. use One-Drive from the c:\. only thing i can thing of is the username is different then the User folder. but they resolve when i cut and past the c:\users\%username%\etc.... in windows explorer

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    On the machines where it fails what does Environ("OneDrive") return?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    too risky if they have multiple one drive folders, don't know how to choose correct one.

  9. #9
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    made some changes and are using Environ("username") seems to be working. so confused why %USERNAME% worked for so long and on all machines until recently. Thanks

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Code:
    Call MakeDir(strFilePath)
    Is that a typo for MkDir() or a seperate procedure?
    Whats your MakeDir() code look like?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Glad to hear you got it working, not sure what you meant by multiple OneDrive folders, I thought the current (logged in) user can only have one.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    Users can have multiple one drive folders. One is set to their desktop, etc…

  13. #13
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am guessing you are looking up "UserVenuePath" in a table (tbl_SystemInfo) in the current dB (which is supposed to evaluate to a user's name?).
    The path points to One Drive; somehow you get the Caterer Name (is there more than one Caterer?).


    Looking at the posted code:
    Code:
    Private Sub Command276_Click()  Terrible name for a button (I am guessing it is a button).
    You are referencing 3 controls on form "frm_Contract" using syntax like
    Code:
    Form_frm_Contract.DateofFunction
    "Form_frm_Contract" is how Access keeps track of form/report object names. It is not a good idea, but you can/could have a FORM named "Test1" AND a REPORT named "Test1"
    In the IDE, the prefix "Form_" and "Report_" is how Access allows for both objects to have the same name.

    You should be using Me.DateofFunction or [Forms]![frm_Contract]![controlname] (<<-- change controlname to the actual control names)


    In the OpenReport command, you need to concatenate the value to the field name.

    if ContractsID is numeric, use
    Code:
      DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = " & [Forms]![frm_Contract]![ContractsID], acWindowNormal
    if ContractsID is text, then use
    Code:
      DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = '" & [Forms]![frm_Contract]![ContractsID] & "'", acWindowNormal

    To export the report to PDF, you don't need to open the report first.
    From help:
    ObjectName (Optional Variant)
    A string expression that's the valid name of an object of the type selected by the ObjectType argument. If you want to output the active object, specify the object's type for the ObjectType argument and leave this argument blank.
    Because you have "strReport" as the ObjectName parameter, the command is not using the selected object - it is using the saved report. Hopefully the report record source has a WHERE clause.


    Consider this code (rename the sub - maybe "btnExportRptToPDF):
    Code:
    Private Sub Command276_Click()
    
        Dim UserVenuePath As String
        Dim strFilePath As String
        Dim strReport As String
    
        '    DoCmd.RunCommand acCmdSaveRecord
        Me.Dirty = False
    
        UserVenuePath = DLookup("[FilePath]", "tbl_SystemInfo", "[SystemInfoID] = 1")
        strFilePath = UserVenuePath & "\Contracts\" & Format(Forms!frm_Contract.DateofFunction, "MM-DD-yyyy") & "\" & Forms!frm_Contract.DayTimeFunction & "\"
        strFileName = Forms!frm_Contract.NameonContract & ".pdf"
    
        If FolderExists(strFilePath) = False Then
            Call MakeDir(strFilePath)
        Else
            MsgBox "This folder already exists.", vbInformation, "Folder Exists"
        End If
    
        strReport = "rpt_Contract"
    
        'Save the report to .PDF
        DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFilePath & strFileName, False
    
        'Display Message
        MsgBox "New file has created successfully in the new folder!", vbInformation, "VBAF1"
    
    End Sub

  14. #14
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    this code wants to print every contract in the system. need to open and set criteria DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = [Forms]![frm_Contract]![ContractsID]", acWindowNormal

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115

    DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = [Forms]![frm_Contract]![ContractsID]", acWindowNormal

    DoCmd.OpenReport strReport, acViewPreview, , "[ContractsID] = " & [Forms]![frm_Contract]![ContractsID], acWindowNormal
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. DB design same unique ID between two systems
    By johnseito in forum Database Design
    Replies: 8
    Last Post: 10-17-2018, 11:15 AM
  2. Replies: 4
    Last Post: 08-21-2012, 11:10 AM
  3. Operating systems
    By nashr1928 in forum Access
    Replies: 3
    Last Post: 12-05-2011, 03:24 PM
  4. Student Information Systems
    By DrCreosote in forum Access
    Replies: 1
    Last Post: 09-29-2010, 06:33 PM
  5. systems tables
    By ldbeeman in forum Access
    Replies: 2
    Last Post: 09-18-2010, 05:42 AM

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