T
Tim
Hi folks,
I use the following code to print to pdf file from access module. The code
looks fine and work. But, when I rebooted my system, I will have a problem
to run the code. It frozen during printing. If I forced to close and
reopened Access again, then it worked. If I reboot my system, it happened
again. Could anyone help me to resolve the issue? I really appreciate your
help.
PS: I am using window XP and office 2003
Thanks in advance.
Tim.
Const HKEY_CLASSES_ROOT As Long = &H80000000
Const HKEY_CURRENT_USER As Long = &H80000001
Const HKEY_LOCAL_MACHINE As Long = &H80000002
Const HKEY_USERS As Long = &H80000003
Const HKEY_CURRENT_CONFIG As Long = &H80000005
Const HKEY_DYN_DATA As Long = &H80000006
Public Function fRegKeyCreate(lngHKey As Long, strKeyPath As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
Set objRegistry = Nothing
End Function
Public Function fRegKeyDelete(lngHKey As Long, strKeyPath As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.DeleteKey lngHKey, strKeyPath
Set objRegistry = Nothing
End Function
Public Function fRegValueCreate(lngHKey As Long, strKeyPath As String, _
strName As String, strValue As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.SetStringValue lngHKey, strKeyPath, _
strName, strValue
Set objRegistry = Nothing
End Function
Function fOutputPDF(strFileName As String, strAccessPath As String, _
strReportName) As String
Dim prtNew As Printer
Dim prtOriginal As Printer
Dim strKeyPath As String
strKeyPath = "Software\Adobe\Acrobat Distiller\PrinterJobControl"
Set prtOriginal = Application.Printer
Set prtNew = Application.Printers("Adobe PDF")
Set Application.Printer = prtNew
fRegKeyDelete HKEY_CURRENT_USER, strKeyPath
fRegKeyCreate HKEY_CURRENT_USER, strKeyPath
fRegValueCreate HKEY_CURRENT_USER, strKeyPath, strAccessPath, strFileName
DoCmd.OpenReport strReportName
fRegKeyDelete HKEY_CURRENT_USER, strKeyPath
Application.Printer = prtOriginal
Set prtNew = Nothing
End Function
Public Sub test()
fOutputPDF "c:\temp\1.pdf", _
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE", "1"
fOutputPDF "c:\temp\2.pdf", _
"C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE", "2"
End Sub
I use the following code to print to pdf file from access module. The code
looks fine and work. But, when I rebooted my system, I will have a problem
to run the code. It frozen during printing. If I forced to close and
reopened Access again, then it worked. If I reboot my system, it happened
again. Could anyone help me to resolve the issue? I really appreciate your
help.
PS: I am using window XP and office 2003
Thanks in advance.
Tim.
Const HKEY_CLASSES_ROOT As Long = &H80000000
Const HKEY_CURRENT_USER As Long = &H80000001
Const HKEY_LOCAL_MACHINE As Long = &H80000002
Const HKEY_USERS As Long = &H80000003
Const HKEY_CURRENT_CONFIG As Long = &H80000005
Const HKEY_DYN_DATA As Long = &H80000006
Public Function fRegKeyCreate(lngHKey As Long, strKeyPath As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
Set objRegistry = Nothing
End Function
Public Function fRegKeyDelete(lngHKey As Long, strKeyPath As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.DeleteKey lngHKey, strKeyPath
Set objRegistry = Nothing
End Function
Public Function fRegValueCreate(lngHKey As Long, strKeyPath As String, _
strName As String, strValue As String)
Dim objRegistry
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
objRegistry.SetStringValue lngHKey, strKeyPath, _
strName, strValue
Set objRegistry = Nothing
End Function
Function fOutputPDF(strFileName As String, strAccessPath As String, _
strReportName) As String
Dim prtNew As Printer
Dim prtOriginal As Printer
Dim strKeyPath As String
strKeyPath = "Software\Adobe\Acrobat Distiller\PrinterJobControl"
Set prtOriginal = Application.Printer
Set prtNew = Application.Printers("Adobe PDF")
Set Application.Printer = prtNew
fRegKeyDelete HKEY_CURRENT_USER, strKeyPath
fRegKeyCreate HKEY_CURRENT_USER, strKeyPath
fRegValueCreate HKEY_CURRENT_USER, strKeyPath, strAccessPath, strFileName
DoCmd.OpenReport strReportName
fRegKeyDelete HKEY_CURRENT_USER, strKeyPath
Application.Printer = prtOriginal
Set prtNew = Nothing
End Function
Public Sub test()
fOutputPDF "c:\temp\1.pdf", _
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE", "1"
fOutputPDF "c:\temp\2.pdf", _
"C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE", "2"
End Sub