WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Problem Getting Record Count via ADO


Question:

I am attempting to determine if a row exists in a table by using the .RecordCount property of a RecordSet. However, all I ever seem to get for the recordcount is -1. Here's the relevant code, and attached is a debug trace of the complete program up to the line in question.

WB 2003h, Office XP, XPPro.

  AccessConn = StrCat('Provider=MicroSoft.Jet.OLEDB.4.0; Data Source="', DataBaseFile, '";')
  AccessDB = ObjectOpen('ADODB.Connection')
  AccessDB.open(AccessConn)

  rsCount = ObjectOpen('ADODB.RecordSet')
  rsCount.CursorLocation = adUseServer
  rsCount.CursorType = adOpenDynamic
  rsCount.LockType = adLockOptimistic

  rsSSN = ObjectOpen('ADODB.RecordSet')
  rsSSN.CursorLocation = adUseServer
  rsSSN.CursorType = adOpenDynamic
  rsSSN.LockType = adLockOptimistic

  CountQuery = "SELECT SSN FROM Eligible WHERE EmplID = '"
  SSNQuery = "SELECT prsn_soc_sec_nbr FROM dss.pse_emplid_map_gt WHERE prsn_univ_id = '"

  SSNQuerySql = StrCat(SSNQuery, EmplID, "'")
  rsSSN.Open(SSNQuerySQL, OracleConn)
  fSSN = rsSSN.Fields('prsn_soc_sec_nbr')
  SSN = fSSN.Value
  rsSSN.Close         ;close the SSN Query
  ;See if he's in the db already
  CountQuerySQL = StrCat(CountQuery, EmplID, "'")
  rsCount.Open(CountQuerySQL, AccessConn)
  ssncount = rsCount.Fields('ssn')
  ;I do get the desired value for SSN here in X
  x = ssncount.value
  ;but Count comes out -1 every time!
  Count = rsCount.RecordCount
  If Count > 0   ;he is, so update the record

Answer:

you may have to try adUseClient for the Access Connection; but if using adUseServer, you often have to
RS.Movelast()
RS.MoveFirst()

..then

x= RS.RecordCount
to insure the entire Recordset is loaded, or just use a forward-only cursor.

User Reply:

adUseClient took care of it.
Article ID:   W16083
File Created: 2004:03:30:15:42:46
Last Updated: 2004:03:30:15:42:46