Discussion:
VB6 dll used with Word 2003
(too old to reply)
Ian Bayly
2007-11-11 23:53:21 UTC
Permalink
I have a VB6 dll which is referenced in Word 2003.
I also have the dll running as part of a VB Group so I can test from the VB
IDE.
The dll works fine on my development PC so I packaged it and ran a test
install on another PC.(Both XPPro but different SP levels)
Very frustrating - my start-up function will not run from Word, but WILL run
from my VB IDE on the new PC.
The start-up function calls a login form, requests a Name/Password, encrypts
them and then checks in an MDB whether the logon is valid.
The code fails when creating a recordset using ADO with message "Error
number: 91 Object variable or with block variable not set."
By inserting msgboxes all paths etc are initialising correctly.
Again I emphasise - It runs fine from VB IDE and runs fine from Word on the
development PC, but fails when called from Word on the test PC.

I'm getting fairly desperate!!! Any help appreciated.

TIA

Ian B


Code snips below
from Login Form where error occurs at line 90

40 sCryptName = EncryptText(sRawName, txtPassword)
50 sCryptPwd = EncryptText(sRawPwd, txtPassword)
60 Debug.Print sCryptName
70 Debug.Print sCryptPwd
80 sSQL = "Select * from tblUser WHERE tblUser.UserName= '" & sCryptName
& "'"
90 Call GetRecordset(sSQL)
FAILS HERE

Snip from Public Function GetRecordSet (myRS is a global variable)
Dim myConn As New ADODB.Connection
10 On Error GoTo GetRecordset_Error
20 GetRecordset = False
30 myConn.CursorLocation = adUseClient
40 myConn.Open sConnString & "Data Source = " & sDBPath & ";"
PATH IS CORRECT
50 Set myRs = New ADODB.Recordset
60 myRs.CursorType = adOpenKeyset
70 myRs.LockType = adLockOptimistic
80 myRs.ActiveConnection = myConn
90 myRs.Open (sSQL)
100 Debug.Print sSQL
110 GetRecordset = True
120 On Error GoTo 0
130 Exit Function

Snip from calling Word Macro

10 On Error GoTo xxxLogin_Err
Dim clMain_o As New clMain
20 Call clMain_o.StartAction("Login")
Ian B
2007-11-12 06:55:37 UTC
Permalink
To take this a stage further, on my test PC I copied the dll code into a
word VBA module and was surprised to find I get the same error when running
from VBA, BUT I can now trap the error and it is with the line:
myConn.Open sConnString (40 below)
I am sure the sDBPath (msgbox etc) is correct which leaves the sConnString
variable out of an ini file thus:
ConnString=Provider=Microsoft.Jet.OLEDB.4.0;
The TestPC has msjet40.dll but there may be a difference because development
PC is SP1 not SP2.

As it's Jet I should have stayed with DAO (at least it's consistent) but ...

Any further help appreciated.

Ian B
Post by Ian Bayly
I have a VB6 dll which is referenced in Word 2003.
I also have the dll running as part of a VB Group so I can test from the VB
IDE.
The dll works fine on my development PC so I packaged it and ran a test
install on another PC.(Both XPPro but different SP levels)
Very frustrating - my start-up function will not run from Word, but WILL run
from my VB IDE on the new PC.
The start-up function calls a login form, requests a Name/Password, encrypts
them and then checks in an MDB whether the logon is valid.
The code fails when creating a recordset using ADO with message "Error
number: 91 Object variable or with block variable not set."
By inserting msgboxes all paths etc are initialising correctly.
Again I emphasise - It runs fine from VB IDE and runs fine from Word on the
development PC, but fails when called from Word on the test PC.
I'm getting fairly desperate!!! Any help appreciated.
TIA
Ian B
Code snips below
from Login Form where error occurs at line 90
40 sCryptName = EncryptText(sRawName, txtPassword)
50 sCryptPwd = EncryptText(sRawPwd, txtPassword)
60 Debug.Print sCryptName
70 Debug.Print sCryptPwd
80 sSQL = "Select * from tblUser WHERE tblUser.UserName= '" & sCryptName
& "'"
90 Call GetRecordset(sSQL)
FAILS HERE
Snip from Public Function GetRecordSet (myRS is a global variable)
Dim myConn As New ADODB.Connection
10 On Error GoTo GetRecordset_Error
20 GetRecordset = False
30 myConn.CursorLocation = adUseClient
40 myConn.Open sConnString & "Data Source = " & sDBPath & ";"
PATH IS CORRECT
50 Set myRs = New ADODB.Recordset
60 myRs.CursorType = adOpenKeyset
70 myRs.LockType = adLockOptimistic
80 myRs.ActiveConnection = myConn
90 myRs.Open (sSQL)
100 Debug.Print sSQL
110 GetRecordset = True
120 On Error GoTo 0
130 Exit Function
Snip from calling Word Macro
10 On Error GoTo xxxLogin_Err
Dim clMain_o As New clMain
20 Call clMain_o.StartAction("Login")
Ralph
2007-11-12 16:49:52 UTC
Permalink
Post by Ian B
To take this a stage further, on my test PC I copied the dll code into a
word VBA module and was surprised to find I get the same error when running
myConn.Open sConnString (40 below)
I am sure the sDBPath (msgbox etc) is correct which leaves the
sConnString
Post by Ian B
ConnString=Provider=Microsoft.Jet.OLEDB.4.0;
The TestPC has msjet40.dll but there may be a difference because development
PC is SP1 not SP2.
As it's Jet I should have stayed with DAO (at least it's consistent) but ...
Any further help appreciated.
Ian B
Poor guess you probably have different version of the Jet installed (or
incorrectly registered).
jet
http://www.microsoft.com/downloads/details.aspx?FamilyID=2deddec4-350e-4cd0-a12a-d7f70a153156&DisplayLang=en
MDAC
http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en
Be sure to grab the Component Checker listed at the bottom of the page.
http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en

-ralph

Loading...