Solved

Updating A Record using ADO in VB6

Posted on 2000-03-17
6
273 Views
Last Modified: 2011-10-03
I have this little VB executable that runs on the server that uses ADO to query a recordset and then loop through to see if there is any data in the Comments field.  If there is data it needs to update the record.  The database it is updating is in Access and the field is set in Access to accept zero length strings.  I keep getting "The operation requested is not supported by the provider" every time I try to update the comment field of a record.  Please let me know why I get this error everytime I try to update it?!?!?!  

Here is my code...

Public Sub SendMail()
Dim cnLube As Connection
Dim rstEmail As Recordset
Dim strConnect As String
Dim objMail As CDONTS.NewMail
Dim strBody As String

On Error GoTo Proc_Err


        If Day(Date) = 17 Then
                Set cnLube = New ADODB.Connection
                Set rstEmail = New ADODB.Recordset
                       
                cnLube.Provider = "Microsoft.Jet.OLEDB.3.51"
                cnLube.ConnectionString = "Data Source=C:\inetpub\wwwroot\lubeoil\MyDB_be.mdb;Jet OLEDB:database password=xxxxxxx"
                cnLube.CursorLocation = adUseServer
                cnLube.Open
               
                rstEmail.Source = "Select * FROM tblEmailList"
                Set rstEmail.ActiveConnection = cnLube
                rstEmail.CursorType = adOpenKeyset
                rstEmail.Open
        End If
       
       
       
        If Day(Date) = 17 Then
           
            With rstEmail
                   
                    Do Until .EOF
                        If Not !Comments = "" Then

                            !Comments = ""
                            .Update
                           
                        End If
                        .MoveNext
                    Loop
                   
            End With
       
        End If
       
       
Set rstEmail = Nothing
Set cnLube = Nothing


Proc_Err:
Debug.Print Err.Description

End Sub


0
Comment
Question by:kenadelglass
6 Comments
 

Accepted Solution

by:
mpcapps earned 100 total points
ID: 2629840
put your .edit in before you modify and update :>)
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2630188
mpcapps,

in ADO, we don't put the .Edit mtehod anymore!!!

kenadelglass,

Do this table have a primary index?

Why don't you simply use a SQL Update query? See this sample:

If Day(Date) = 17 Then
   Set cnLube = New ADODB.Connection
                         
   cnLube.Provider = "Microsoft.Jet.OLEDB.3.51"
   cnLube.ConnectionString = "Data Source=C:\inetpub\wwwroot\lubeoil\MyDB_be.mdb;Jet OLEDB:database password=xxxxxxx"
   cnLube.CursorLocation = adUseServer
   cnLube.Open

   cnLube.Execute "Update tblEmailList Set Comments = ''"                
End If
0
 
LVL 3

Expert Comment

by:jetforce
ID: 2631007
The standard open method for ADO recordsets, is read only mode.
try adding rstEmail.LockType=adLockOptimistic.
Also emoreau is right, it is much quicker to use the Update SQL statement and it looks cleaner.


Jetforce
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:kenadelglass
ID: 2631353
emoreau

Yes the table I am updating has a primary key.  I was going to try the SQL statement you suggested but I wanted to try some ADO stuff - primarily for my own learning.

Jetforce - what could I use besides the standard rst.Open?  What does the optimistic locking have to do with whether I can update a record - Nobody is in the database when I am testing so I don't think there is an editing conflict?

thx....
kenadelglass
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2631389
If the recordset is open for "Read only" (the default value) as JetForce mentionned, you can't update.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2635150
Back to basics, in your access database is the Comments field Allow Zero Length Fields property set to Yes?

Emoreau & Jetforce: (From Above)
rstEmail.CursorType = adOpenKeyset
He's covered.
               

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 36
VBA saving file message display 5 56
Paint/Redraw window while dragging 16 68
how to know if my Checkbox is True in VB6.0? 9 36
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now