ADODB Unexpected Results

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am getting SID passed to my subroutine. [According to Debug.Print TypeName(SID) it is datatype long]

In my test I am using SID values of 130 and 131
I know that there is data in the table that will return a single row.
I even tested the query in Access using and got the row.
I had even hard coded the value into the ts.Open statement and it does not show the row it executes the if ts.bof=ts.eof line which stops processing the subroutine.

In the table tsTestSessionID is an autonumber.

Can not figure out what is going on as every other test it works.

Code:
    Dim ts As ADODB.Recordset
    Set ts = New ADODB.Recordset
    ts.ActiveConnection = CurrentProject.Connection
    ts.LockType = adLockReadOnly
    ts.CursorType = adOpenDynamic
    ts.Open "Select * from tblTestSessions Where tsTestSessionID =" & SID
    If Not CK.BOF Then
     ts.MoveFirst
     End If
    If ts.BOF = ts.EOF Then
        MsgBox "Test Session Not Found, Processing Stop", vbCritical, "Error!"
        ts.Close
        Set ts = Nothing
        Exit Sub
     End If 
   ts.Close
   Set ts = Nothing
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Okay, first off -

When opening a new recordset. It is ALWAYS at the beginning so you don't need to movefirst. Second, use either of these instead of your current one:

If ts.BOF AND ts.EOF Then

or just use

If ts.RecordCount = 0 Then

The ADODB recordset's RecordCount will either be 0 if there aren't records returned or 1 if there are records.
 
Upvote 0
Thanks Bob that seems to have worked.

Dont remember where I saw that you needed to make sure it was at the first record... Programming in VBA and with Access is a new skill set that I am developing. I have a stack of books to help.

I took a course in ultra basic VB6 back in college way back in 2001. Havent done much more than simple access querys since.

Thanks again for your help.
 
Upvote 0
You may be thinking of MoveLast where you have to move to the last record and back to the first to get the actual count of the records.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top