0

I have two computers, desktop and a laptop. Both computers have their own version of Access. The database is stored on the C: of the desktop and is used from either the desktop or the laptop.

I have a button that converts a report to a pdf and then puts the pdf in a specific file folder using the date & time as the file name.

The button works find from the desktop, but does not work from the laptop. From the laptop the button will open up the report but that is where the process stops.

Not sure what is missing here, but I would guess that I need something in the file path to distinguish the two computers, or more precisely I need to label so that the pdf document ends up in the desktop and not the laptop as both computers have a c:

Public Sub tabExportPDF_Click()
Dim ToDate As Date
Dim CurrentTime As String
Dim NetWorkPath As String
Dim ExportPath As String

ToDate = Date
CurrentTime = Format(CStr(Now), "hh-mm_ampm")

NetWorkPath = "c:\Users\DHPA\Documents\Digby Harbour Port Association\DHPA Database\Maps\"

ExportPath = NetWorkPath & "\" & "Map_" & ToDate & "_" & CurrentTime & ".pdf"
On Error GoTo ErrHandler

DoCmd.OpenReport "rptMap", acViewPreview
DoCmd.OutputTo acOutputReport, "rptMap", acFormatPDF, ExportPath
DoCmd.Close acReport, "rptMap"

MsgBox prompt:="PDF File exported to: " & vbNewLine & NetWorkPath, buttons:=vbInformation, Title:="Map Exported as PDF"

ErrHandler:
    If Err <> 2501 Then
    End If
End Sub
DHPA
  • 45
  • 7
  • You could try something simple like [getting the name of the computer](https://stackoverflow.com/a/3551071/4717755). – PeterT Oct 13 '22 at 17:50
  • No change when the error handler is removed. The immediate window shows: Debug.Print CurrentProject.Path C:\Users\DHPA\Desktop\DHPA DB Working copy – DHPA Oct 13 '22 at 18:45

1 Answers1

0

You could use the following, just insert proper computer name (of your desktop pc) in place of TargetComputerName

NetWorkPath = "\\TargetComputerName\c$\Users\DHPA\Documents\Digby Harbour Port Association\DHPA Database\Maps\"

ExportPath = NetWorkPath & "Map_" & ToDate & "_" & CurrentTime & ".pdf"

From the comments bellow, on the desktop PC Documents folder is shared probably, so if you are running the code from the laptop, it should use the 2nd path.

If UCase(Environ$("computername")) = "MAIN" Then
    NetworkPath = "\\MAIN\c$\Users\DHPA\Documents\Digby Harbour Port Association\DHPA Database\Maps\"
Else
    NetworkPath = "\\MAIN\Documents\Digby Harbour Port Association\DHPA Database\Maps\"
End If
milo5m
  • 619
  • 1
  • 3
  • 8
  • I've added the computer name and removed the error handler and what comes back is the error is occuring on the line DoCmd.Output so I'm thinking there is still an issue with the NetWorkPath which currently looks like this: NetWorkPath = "\\MAIN\c$\Users\DHPA\Documents\Digby Harbour Port Association\DHPA Database\Maps\" ... Still working fine from the desktop. – DHPA Oct 13 '22 at 18:57
  • Try pasting that networkPath in the File Explorer, just to check if it points out in the right place – milo5m Oct 13 '22 at 19:00
  • after a copy paste one ends up in the final file folder Maps when on the desktop, but doing the same process on the laptop the file folder/path cannot be found – DHPA Oct 13 '22 at 19:05
  • I wasn't clear, if you pasted the path on your laptop and it ends up where it should, the path is okay. If it doesn't end up where it should try setting up C on your desktop as shared drive and see if that works – milo5m Oct 13 '22 at 19:16
  • Ok I'll try that. The file to get to the maps folder when on the laptop looks as follows: \\MAIN\Documents\Digby Harbour Port Association\DHPA Database\Maps\ – DHPA Oct 13 '22 at 19:19