Hiding a dialog box while creating a pdf

  • Thread starter Thread starter Carls
  • Start date Start date
C

Carls

I am creating a pdf file in Access when it prints the
file to my pdf writer it displays a dialog box asking me
for a filename. Is there a way to accept the default
automatically and not display this box? I have tried the
send keys function but it is very inconsistant.
 
Hi Carls,

Do you have any chance to try Keri Hardwick method?

http://www.mvps.org/access/reports/rpt0011.htm

I did not test it however, based on the code line below, we can specify the
filename by code instead of inputting it on the dialog window at run time,
which should be the thing you are after.

Call aht_apiWriteProfileString("Acrobat PDFWriter", _
"PDFFileName", NewFileName)

ChangePdfFileName "Name of pdf file including .pdf"

Please let me know if the above information helps.


Sincerely,

Alick Ye, MCSD
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



--------------------
| Content-Class: urn:content-classes:message
| From: "Carls" <[email protected]>
| X-Tomcat-NG: microsoft.public.access.modulesdaovba
|
| I am creating a pdf file in Access when it prints the
| file to my pdf writer it displays a dialog box asking me
| for a filename. Is there a way to accept the default
| automatically and not display this box? I have tried the
| send keys function but it is very inconsistant.
|
 
Yes it seems so.

Carls, I don't find an easy method so far, however, I believe calling
Windows API can be the "safe" method to perform this task, we can send the
filename string to the dialog window by Windows API; below is a sample to
get start, this sample send string "hello" to notepad window.

Option Compare Database
Option Explicit

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As
Long

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As
_
String, ByVal lpszWindow As String) As Long

Private Const WM_SETTEXT = 12
Private Sub Command0_Click()

ToNotePad "hello"

End Sub

Public Sub ToNotePad(x As String)
'assuming notepad is open
Dim h As Long, ed As Long, t As Long

h = FindWindow("Notepad", "Untitled - Notepad")
If (h <> 0) Then
ed = FindWindowEx(h, 0, "Edit", "")
If (ed <> 0) Then
SendMessage ed, WM_SETTEXT, ByVal 0, ByVal x
Else
MsgBox "Could not find notepad's edit"
End If
Else
MsgBox "Could not find notepad"
End If
End Sub

Please feel free to reply to the thread if you have any questions or
concerns.




Sincerely,

Alick Ye, MCSD
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Allen Browne" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Hiding a dialog box while creating a pdf
|
| Carls has not told us what version of Acrobat they use, but from memory,
| Keri's method is not too helpful with the more recent versions of Acrobat,
| since it relies on a setting in win.ini which the new versions don't read.
|
| --
| Allen Browne - Microsoft MVP. Perth, Western Australia.
|
|
| | > Hi Carls,
| >
| > Do you have any chance to try Keri Hardwick method?
| >
| > http://www.mvps.org/access/reports/rpt0011.htm
| >
| > I did not test it however, based on the code line below, we can specify
| the
| > filename by code instead of inputting it on the dialog window at run
time,
| > which should be the thing you are after.
| >
| > Call aht_apiWriteProfileString("Acrobat PDFWriter", _
| > "PDFFileName", NewFileName)
| >
| > ChangePdfFileName "Name of pdf file including .pdf"
| >
| > Please let me know if the above information helps.
| >
| >
| > Sincerely,
| >
| > Alick Ye, MCSD
| > Microsoft Online Partner Support
| >
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| >
| >
| > --------------------
| > | Content-Class: urn:content-classes:message
| > | From: "Carls" <[email protected]>
| > | X-Tomcat-NG: microsoft.public.access.modulesdaovba
| > |
| > | I am creating a pdf file in Access when it prints the
| > | file to my pdf writer it displays a dialog box asking me
| > | for a filename. Is there a way to accept the default
| > | automatically and not display this box? I have tried the
| > | send keys function but it is very inconsistant.
|
|
|
 
I have no problem with sending the file name to the
dialog box. I just need to hide the dialog box. Using
the send keys"{enter}" has worked the best so far but it
isn't a 100%. I have tried the code you asked me to
check out and it doesn't get rid of the dialog box, it
basically gets me to the same place i am now. By the way
i am using Windows XP and acrobat 5.0 and the win.ini
changes had no effect on the way the program handles the
dialog box.
 
You need to edit the registry in to bypass the SaveAs dialog,
Example:
?SetRegValue(HKEY_CURRENT_USER, "Software\Adobe\Acrobat PDFWriter",
"PDFFileName", "C:\Temp\Demo.pdf")


Careful with the line wraps.
'--------------START CODE ------------------------
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CURRENT_CONFIG = &H80000004
Public Const HKEY_DYN_DATA = &H80000005

Public Const REG_SZ = 1 'Constant for a string variable type.
Public Const REG_DWORD = 4 '32-bit number

Private Declare Function RegOpenKeyA Lib "advapi32.dll" (ByVal HKEY As Long,
ByVal sSubKey As String, ByRef hkeyResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long)
As Long
Private Declare Function RegSetValueExA Lib "advapi32.dll" (ByVal HKEY As
Long, ByVal sValueName As String, ByVal dwReserved As Long, ByVal dwType As
Long, ByVal sValue As String, ByVal dwSize As Long) As Long
Private Declare Function RegCreateKeyA Lib "advapi32.dll" (ByVal HKEY As
Long, ByVal sSubKey As String, ByRef hkeyResult As Long) As Long
'Private Declare Function RegQueryValueExA Lib "advapi32.dll" (ByVal HKEY As
Long, ByVal sValueName As String, ByVal dwReserved As Long, ByRef lValueType
As Long, ByVal sValue As String, ByRef lResultLen As Long) As Long

Function SetRegValue(ByVal HKEY As Long, ByVal path As String, ByVal entry
As String, ByVal Value As String) As Boolean
On Error GoTo Proc_Error
'Set text value in registry
'EXAMPLE: SetRegValue(HKEY_CURRENT_USER, "Software\Adobe\Acrobat
PDFWriter", "PDFFileName", "C:\Temp\Demo.pdf")
Dim lngRetVal As Long

If HKEY = 0 Then GoTo Proc_Exit
If RegOpenKeyA(HKEY, path, lngRetVal) <> 0 Then
RegCreateKeyA HKEY, path, lngRetVal
End If

SetRegValue = (RegSetValueExA(lngRetVal, entry, 0&, 1&, Value,
Len(Value) + 1) = 0)

Proc_Exit:
RegCloseKey lngRetVal
Exit Function

Proc_Error:
MsgBox Err.Description, vbCritical
Resume Proc_Exit
End Function
'----------------- END CODE ----------------

HTH

Jose
 
Back
Top