I am having a problem running my .exe as service using
NTSVC.OCX. Everything works fine if i just execute
the .exe, but running the .exe as a service is having a
problem. It just started happening now and i have no idea
why. It was working fine earlier and all of a sudden i
started getting error = 91 (Object variable or With block
variable not set). I have a Public Sub that calls a
function to find the printer details and then print the
file using shell execute. i will paste the code below for
the module as well as for the sub.
Retreive the
vb object "printer" corresponding to the
BAS module
'MS Windows API Function Prototypes
private Declare Function GetProfileString Lib "kernel32"
Alias _
"GetProfileStringA" (byval lpAppName as string, _
byval lpKeyName as string, byval lpDefault as
string, _
byval lpReturnedString as string, _
byval nSize as Long) as Long
'---------------------------------------------------------
------
' Retreive the
vb object "printer" corresponding to the
window's
' default printer.
'---------------------------------------------------------
------
public Function GetDefaultPrinter() as Printer
Dim strBuffer as string * 254
Dim iRetValue as Long
Dim strDefaultPrinterInfo as string
Dim tblDefaultPrinterInfo() as string
Dim objPrinter as Printer
' Retreive current default printer information
iRetValue = GetProfileString
("windows", "device", ",,,", strBuffer, 254)
strDefaultPrinterInfo = Left(strBuffer, InStr
(strBuffer, Chr(0)) - 1)
tblDefaultPrinterInfo = Split
(strDefaultPrinterInfo, ",")
for Each objPrinter In Printers
If objPrinter.DeviceName = tblDefaultPrinterInfo
(0) then
' Default printer found !
Exit for
End If
next
' If not found, return nothing
If objPrinter.DeviceName <> tblDefaultPrinterInfo(0)
then
set objPrinter = nothing
End If
set GetDefaultPrinter = objPrinter
End Function
Now to test the routine, place the following code into a
Form:
Private Sub Form_Load()
Call Process_Printer()
End Sub
Public Sub Process_Printer()
Dim objPrinter as Printer
set objPrinter = GetDefaultPrinter()
MsgBox "Default printer is: " +
objPrinter.DeviceName ----> "THIS IS WHERE THE ERROR
OCCURS"
set objPrinter = nothing
End Sub
Any help would be greatly appreciated!!!
sk