Advertisement

01.28.2005 at 02:16AM PST, ID: 21292272
[x]
Attachment Details

Change of code from DAO to ADO

Asked by SQL_Stu in Microsoft Access Database

Tags: ado, change

The below code used to work with DAO - I've now changed it to ADO and although the query is valid and there are 2 records returned when I run the query in Query Design, the recordcount is always -1.  Anyone got an idea why this might be?

Private Sub UpdateData(dMyDate as Date, lID as Long, sCriteria as String)
Dim sSQL As String, sSearchStr As String
Dim rst1 As New ADODB.Recordset
Dim sCurrPair As String
Dim sCriteria as String

sSearchStr = "[FieldA] = '" & sCriteria & "'"

sSQL = "Select ID, FieldA, FieldB, FieldC,FieldD, FieldE, " & _
    "FieldF, FieldG, FieldH from tbl where " & sSearchStr & _
    " AND [FieldF] = #" & Format(dMyDate, "mm/dd/yy") & "#"

' sSQL is equal to:
' Select ID, FieldA, FieldB, FieldC, FieldD, FieldE, FieldF, FieldG, FieldH from tbl where [FieldF] = 'data' AND [FieldF] = #01/03/06#

rst1.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic, adCmdText

If rst1.RecordCount = -1 Then
Start Free Trial
 
Loading Advertisement...
 
[+][-]01.28.2005 at 02:21AM PST, ID: 13161690

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Access Database
Tags: ado, change
Sign Up Now!
Solution Provided By: ryancys
Participating Experts: 1
Solution Grade: A
 
 
[+][-]01.28.2005 at 02:23AM PST, ID: 13161702

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.28.2005 at 02:37AM PST, ID: 13161855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32