Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2003, 12:03 PM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default NTSVC.OCX and Error = 91

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
 
Old October 20th, 2003, 07:30 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

No answer to your question apart that nothing changes at it's own will - probably you did some smaller change which did not notice.

As I also have to deal with services - have you seen that service starting at bootup on NT does not start on W2k?
Events in eventlog are 7000 and 7009...

Regards,
Felix
 
Old October 23rd, 2003, 08:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you check that your account has a default printer assigned?
Before using objPrinter (in the ProcessPrinter), check if it not nothing (because this is the case), and in case print another message (like no default printer for this account)

Marco
 
Old October 24th, 2003, 01:18 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...or you changed startup account for that service and account has no printer assigned?

Umm... BTW... What if the account is LocalSystem? Can THAT have a default printer assigned?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 91 GVBGVB Excel VBA 2 April 4th, 2008 12:56 AM
error 91 skrj02 Excel VBA 4 May 7th, 2007 11:01 AM
error 91 issues. kd8con Beginning VB 6 1 October 30th, 2006 09:50 AM
Use of NTSVC.OCX jmtoet Pro VB 6 12 June 7th, 2005 05:00 PM
NTSVC.OCX app and Windows 2000 felixs Pro VB 6 10 November 10th, 2004 05:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.