Hi,
I am getting different behavior between running my code in VB6 IDE and after
creating an EXE.
In the LostFocus code given below, I have two messages being displayed,
namely, Msg-1 and Msg-2.
When I run it in IDE, I get same messages for Msg-1 and Msg-2.
But when I create an EXE and run it, Msg-1 shows RecordCount = 1 and .Source
as what was set and Msg-2 shows RecordCount = 198 and .Source = SELECT ...
FROM Client. Yes I do have table named Client with 198 rows in my database
and I do use this SELECT ... FROM Client in a GotFocus event after finishing
with the given LostFocus event But how can this happen?
The database I am using is Sybase ASE 15.0.2
I open the ADODB connection in the Form_Load as follows:
Set oConn = New ADODB.Connection
Set rs = New ADODB.Recordset
'make connection with DBMS
With oConn
.ConnectionString = "DSN=ASE15_MY_DB;UID=sa"
.CursorLocation = adUseClient
.Mode = adModeReadWrite
.Open
If .State = adStateOpen Then
.Execute "USE MY_DB", , adCmdText
End If
End With
Then in a LostFocus event, I have the following code:
With rs
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = oConn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = "SELECT ... FROM Project WHERE ProjectCode = '" +
txtProjectCode.Text + "'"
.Open
If .State = adStateOpen And .RecordCount > 0 Then
MsgBox "Msg-1: The RecodCount = " + Format$(.RecordCount, "#") +
" .Source = " + .Source
iAns = MsgBox("The entered project code already exists." +
vbNewLine + vbNewLine + "Do you want to add a NEW INSTANCE of the same
project?", vbYesNo + vbQuestion, "Entering Project Code")
If iAns = vbYes Then
MsgBox "Msg-2: The RecodCount = " + Format$(.RecordCount, "#")
+ " .Source = " + .Source
--- some more code ---
EndIf 'end of iAns = vbYes
EndIf 'end of .State = adStateOpen And .RecordCount > 0
End With
Richard Mueller [MVP] - 28 Aug 2008 17:06 GMT
> Hi,
>
[quoted text clipped - 62 lines]
>
> End With
Your cursorType does not support RecordCount. See this link:
http://support.microsoft.com/kb/194973
If you need to know if there are any records in the recordset, use the EOF
property of the recordset. If you need the number of records, it might be
more reliable to use the COUNT sql function. Otherwise, use a cursorType
that supports RecordCount.

Signature
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
SME - 28 Aug 2008 17:36 GMT
In the article you provided, it mentions that RecordCount may return -1 for
unsupported CursorType. OK, taking that I may not get correct value for the
RecordCount, I can test for EOF. However, this CursorType usage had been
working for years, particularly with Access and Sybase ASE, on Windows 2000
and XP. I had been copying the same code from other working programs.
But what about "Source"?. Why it is changing? It appears that the rs object
itself is now reflecting some other object than that I set in the given
LostFocus event. Do you mean to say that if I test for EOF the problem would
be solved?
ThanQ...
>> Hi,
>>
[quoted text clipped - 71 lines]
> more reliable to use the COUNT sql function. Otherwise, use a cursorType
> that supports RecordCount.
Jan Hyde (VB MVP) - 29 Aug 2008 11:19 GMT
"SME" <smelchuri@hotmail.com>'s wild thoughts were released
on Thu, 28 Aug 2008 11:45:59 -0400 bearing the following
fruit:
>Hi,
>
>I am getting different behavior between running my code in VB6 IDE and after
>creating an EXE.
Events can fire differently in the EXE vs the IDE which is
why you must always test with a compiled version.
Sounds like it would be worth you putting in some debugging
in certain event to see what's happening.
J
>In the LostFocus code given below, I have two messages being displayed,
>namely, Msg-1 and Msg-2.
[quoted text clipped - 57 lines]
>
> End With
--
Jan Hyde (VB MVP)
https://mvp.support.microsoft.com/profile/Jan.Hyde