Write Registry Problem - Urgent.

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
 
T

Tim

Hi Alex,

Thanks for the info but it can't be worked in my case because I can't put
anything in Windows directory. Do you have any other idea?

Thanks in advance.

Tim.
 
S

Stephen Lebans

The DLL's do not have to be placed in the Windows folder. The docs state to
place the DLL's in either the WIndows folder or the same folder as the front
end of your MDB.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top