Using Albert D.Kallal’s SetDefaultPrinter function for Access 2000 (code below) when it comes to line;
Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows")
the Access freezes and has to be end tasked. What is the issue and how can I fix it?
Function SetDefaultPrinter(strPrinterName As String) As Boolean Dim strDeviceLine As String Dim strBuffer As String Dim lngbuf As Long ' get the full device string ' strBuffer = Space(1024) lngbuf = GetProfileString("PrinterPorts", strPrinterName, "", strBuffer, Len(strBuffer)) 'Write out this new printer information in ' WIN.INI file for DEVICE item If lngbuf > 0 Then strDeviceLine = strPrinterName & "," & _ fstrDField(strBuffer, Chr(0), 1) & "," & _ fstrDField(strBuffer, Chr(0), 2) Call WriteProfileString("windows", "Device", strDeviceLine) SetDefaultPrinter = True ' Below is optional, and should be done. It updates the existing windows ' so the "default" printer icon changes. If you don't do the below..then ' you will often see more than one printer as the default! The reason *not* ' to do the SendMessage is that many open applications will now sense the change ' in printer. I vote to leave it in..but your case you might not want this. ' Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, ByVal "windows") Else SetDefaultPrinter = False End If End Function
Are you certain the API declaration for "SendMessage" is correct?
For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. "Don't confuse fame with success. Paris Hilton is one; Helen Keller is the other." - with apologies to Erma Bombeck for paraphrasing her words.
It appears there is more to Albert's code than what you have posted here. Are you using the entire code sample?
Here is a link with a more complete code sample:
1. What version of Windows and Access are you creating this for?
2. Do you want to change the default printer of Windows or just the printer used for Access?
Please try to further explain why you are trying to use this code which is at least 10 years old. There may be a better approach to take for newer systems.