DoCmd.OutputTo (1 Viewer)

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Good morning chaps,

Small Issue came up.......

Code:
Private Sub PrintInvoice()
Dim strfullpath As String
Dim varfolder As String
    varfolder = "S:\NATIONAL HOTELS\99 Project Database\Files\InvoiceApprovals"
    strfullpath = varfolder & "\" & Me.VendorName & " " & Me.InvNo & ".pdf"
    DoCmd.OutputTo acOutputReport, "rptInvoiceEntry", acFormatPDF, strfullpath, True
    DoCmd.Close acReport, "rptInvoiceEntry", acSaveNo
End Sub

Above works on my laptop perfectly, but on another PC it seems to get stuck DoCmd.output line, on screen it looks like exporting but nothing saved as PDF (only some.tmp file) and doesnt open the exported report for viewing

Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:44
Joined
May 7, 2009
Messages
19,229
on another pc, does he has read/write write and can access the varfolder?
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:44
Joined
Sep 21, 2011
Messages
14,238
Perhaps add DoEvents before closing report. Might be a timing issue?
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Perhaps add DoEvents before closing report. Might be a timing issue?
Nope, didn't help......

Very strange.......I will try on a different PC later on to see if the current one has issues
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Nope, didn't help......

Very strange.......I will try on a different PC later on to see if the current one has issues
Doesnt work on another PC as well......

Is there any alternative for this?

Code:
DoCmd.OutputTo acOutputReport, "rptInvoiceEntry", acFormatPDF, strfullpath, True
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:44
Joined
Sep 21, 2011
Messages
14,238
All they all using the same mapped drive? ie S:
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:44
Joined
Feb 28, 2001
Messages
27,148
These are usually tedious to find. When something works on machine A but fails on machine B (or C or D...) then the problem is always one of two or three things.

1. Permissions on the destination folder where you want to write the file. To test, use Windows File Explorer, get to the destination folder, then RIGHT CLICK on it to get properties, select Permissions, and on that dialog, find "Effective Permissions." Do this on a working machine and on one that fails.

2. Malformed path specification. In the code, once you have formed strFullPath, use a Debug.Print on it. You must have the VBA window open and View >> Immediate Window, which is where Debug.Print stuff shows up. Look at the path and watch for illegal characters - things that cannot be part of a file name.

3. Compare the references. Again in the VBA windows, look at Tools >> References for a working and a non-working system. Compare them.

4. Gasman's suggestion is also a valid possibility for your problem. Drive mapping is a per-PC definition, not shared among machines. (I.e. each one must be set up separately.)

5. You didn't say if you have a full-blown domain setup, but it is possible that your MACHINE has different permissions than your domain username, and that the other machines have more restrictive permissions. That question might have to be referred to your IT folks, but should show up in the "Effective Permissions" display when performed on a non-working machine.

There might be more, but this is what I recall off the top of my head.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:44
Joined
Oct 29, 2018
Messages
21,455
Are all the machines using the same version of Access and do the other machines have the MS PDF printer driver installed? Try changing the format to Text or RTF, just for testing.
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
These are usually tedious to find. When something works on machine A but fails on machine B (or C or D...) then the problem is always one of two or three things.

1. Permissions on the destination folder where you want to write the file. To test, use Windows File Explorer, get to the destination folder, then RIGHT CLICK on it to get properties, select Permissions, and on that dialog, find "Effective Permissions." Do this on a working machine and on one that fails. All permissions are same

2. Malformed path specification. In the code, once you have formed strFullPath, use a Debug.Print on it. You must have the VBA window open and View >> Immediate Window, which is where Debug.Print stuff shows up. Look at the path and watch for illegal characters - things that cannot be part of a file name. Same routine works on my pc with the same credentials ie report input

3. Compare the references. Again in the VBA windows, look at Tools >> References for a working and a non-working system. Compare them.

4. Gasman's suggestion is also a valid possibility for your problem. Drive mapping is a per-PC definition, not shared among machines. (I.e. each one must be set up separately.) This particular drive is mapped across, for those using the db, as I mentioned earlier, other save functions to same drive/folder working properly, only output to pdf dont

5. You didn't say if you have a full-blown domain setup, but it is possible that your MACHINE has different permissions than your domain username, and that the other machines have more restrictive permissions. That question might have to be referred to your IT folks, but should show up in the "Effective Permissions" display when performed on a non-working machine. Naah, no full blown domain setup here, I would even say its very basic

There might be more, but this is what I recall off the top of my head. Thank you, much appreciated
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Are all the machines using the same version of Access and do the other machines have the MS PDF printer driver installed? Try changing the format to Text or RTF, just for testing.
I'll test this tomorrow, but both machines do print to MS PDF under printer options

Very frustrating......
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:44
Joined
Feb 28, 2001
Messages
27,148
Revisiting...

2. Malformed path specification. In the code, once you have formed strFullPath, use a Debug.Print on it. You must have the VBA window open and View >> Immediate Window, which is where Debug.Print stuff shows up. Look at the path and watch for illegal characters - things that cannot be part of a file name

Check the folder settings to be sure you don't have 8-3 vs. advanced filename settings. The 8-3 case (old Windows behavior) restricts which special characters you can use.

Another security-related setting is the trust center selections which vary from machine to machine - i.e. can be machine-specific. Because what you are looking for is that difference between a working and non-working machine. This one is particularly elusive.
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Revisiting...



Check the folder settings to be sure you don't have 8-3 vs. advanced filename settings. The 8-3 case (old Windows behavior) restricts which special characters you can use.

Another security-related setting is the trust center selections which vary from machine to machine - i.e. can be machine-specific. Because what you are looking for is that difference between a working and non-working machine. This one is particularly elusive.
Thank you sir, what I have done is, as I have no control over vendor names (quite possibly they will have /,& etc, I removed that portion of strFullPath, I will test again this morning, will update later
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:44
Joined
Feb 28, 2001
Messages
27,148
Here are some cases where, vendor preference or not, you can't use the characters.





There are some variant opinions on things like AMPERSAND and PERCENT and HASHTAG (actually, OCTOTHORPE, but that name is rarely used.) Depending on the context of the file name, you can have a serious problem.
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Here are some cases where, vendor preference or not, you can't use the characters.





There are some variant opinions on things like AMPERSAND and PERCENT and HASHTAG (actually, OCTOTHORPE, but that name is rarely used.) Depending on the context of the file name, you can have a serious problem.
OK, this is what I have done,

Code:
Private Sub PrintInvoice()
Dim strfullpath As String
Dim varfolder As String

    varfolder = "S:\NATIONAL HOTELS\99 Project Database\Files\InvoiceApprovals\"
    strfullpath = varfolder & Me.InvNo & ".pdf"
   
    DoCmd.OutputTo acOutputReport, "rptInvoiceEntry", , strfullpath, True

End Sub

I removed the file type section to get Access to ask,

1. When I choose PDF, command runs, outputs something and stops, saves a tmp file
2. When I choose RTF, command runs correctly, saves the file with pdf extension as specified in the code and tries to open the file with Acrobat reader

So its not folder rights, naming, and any other idea we came up with above.....

Should I get IT to update MS PDF? Re-install Acrobat Reader DC?

Any more ideas?

Is there a VBA code does the same as Do,Cmd.OutputTo ?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:44
Joined
Feb 28, 2001
Messages
27,148
Regarding your post #17:

The problem in your #2 case in that post is that explicit file type that doesn't correspond to the way you wrote the file.

There is a thing called an "Association" - in which Windows associates an application to a file type. You know that the association exists because the icon used to represent the file changes based on file types. If you write a file of any particular file type and then try to open that file, it will run the application associated with the specific file type. So your #2 case occurred because you wrote a file with a type of .PDF but selected .RTF as its internal format. The .PDF points to your installed Adobe program, which means that Adobe looks at that file written as an RTF, sees the wrong internal header info, and asks "WTF do you want me to do with this?"

You can verify that has happened because you can RIGHT-click that file and use an "Open With" option and select WORD or WORDPAD. But whatever you do, DO NOT check the option to "Always use this choice to open..." because if you do, you break the association for .PDF and you'll never be able to properly open the .PDF files again until you repair the association (by using the "Open with..." option again and correctly choosing your Adobe product.)

The problem with your #1 case is what needs to be investigated. The issue with the #2 case is, don't do that 'cause it won't work. And your test #2 does not eliminate the real problem (whatever it is) because your #2 sequence is an operational error.

I'm going to re-iterate that that some utilities will not accept certain characters in file names. Don't know what Adobe will take, but you need DESPERATELY to find out what the full path looks like when you try to create the file. By the way, in the #1 case ... when something writes this .TMP file and stops, does the name portion of the .TMP file match the name you tried to use for output?
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Regarding your post #17:

The problem in your #2 case in that post is that explicit file type that doesn't correspond to the way you wrote the file.

There is a thing called an "Association" - in which Windows associates an application to a file type. You know that the association exists because the icon used to represent the file changes based on file types. If you write a file of any particular file type and then try to open that file, it will run the application associated with the specific file type. So your #2 case occurred because you wrote a file with a type of .PDF but selected .RTF as its internal format. The .PDF points to your installed Adobe program, which means that Adobe looks at that file written as an RTF, sees the wrong internal header info, and asks "WTF do you want me to do with this?"

You can verify that has happened because you can RIGHT-click that file and use an "Open With" option and select WORD or WORDPAD. But whatever you do, DO NOT check the option to "Always use this choice to open..." because if you do, you break the association for .PDF and you'll never be able to properly open the .PDF files again until you repair the association (by using the "Open with..." option again and correctly choosing your Adobe product.)

The problem with your #1 case is what needs to be investigated. The issue with the #2 case is, don't do that 'cause it won't work. And your test #2 does not eliminate the real problem (whatever it is) because your #2 sequence is an operational error.

I'm going to re-iterate that that some utilities will not accept certain characters in file names. Don't know what Adobe will take, but you need DESPERATELY to find out what the full path looks like when you try to create the file. By the way, in the #1 case ... when something writes this .TMP file and stops, does the name portion of the .TMP file match the name you tried to use for output?
Hi Docman,

Issue lays with PDF on the other PC , so i'm totally ignoring No 2, shizzle works as far as Im concerned.....

Fullpath is going to be bit difficult as DB is runs with menus, protected etc and can't have the VBA side open, maybe I'll put a msgbox to see, but I don't think there's an issue with the path, works on my machine, works for RTF on other machine - I'll drag the IT tomorrow and let him uninstall acrobat and re-install etc and see what happens

Also, is there any other way of doing this via VBA? In the event this doesn't work on other PC's I need to come up with another solution

ANd, thanks for yours and other's input on this strange mishap !
 

TajikBoy

Member
Local time
Yesterday, 22:44
Joined
Mar 4, 2011
Messages
82
Hi DocMan !

Got the error message happening in the background,

2501.jpg


How can we fix this sir?
 

Users who are viewing this thread

Top Bottom