Solved

Runtime error 3251 Current Recordset does not support updating

Posted on 2002-06-10
3
9,601 Views
Last Modified: 2011-08-18
The following is a chopped down version of my code... I have removed everything except the code dealing with the recordset...  Please let me know what I need to add to open this up in read/write.  (It stops on the rs.Addnew and displays the error Runtime error '3251' Current Recordset does not support updating.  This may be a limitation of the Provider, or of the select Locktype).

Thanks!
Matt

======== Code ==========
Dim cn As New ADODB.Connection
Dim rsMain As New ADODB.Recordset

cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\Website Projects\ExitCashFlow\logMaster\Logs.mdb;"

strSQL = "Select * From Main Where Username = '" & strQuery & "' and Domain = '" & strDomain & "'"
   
Set rsMain = cn.Execute(strSQL)
   
If rsMain.EOF Then
     rsMain.AddNew
        rsMain(UserName) = strQuery
End If

rsMain.Close
Set rsMain = Nothing

======= End of Code =========
0
Comment
Question by:Voltec
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 7066442
Try this:

Dim cn As ADODB.Connection
Dim rsMain As ADODB.Recordset

set cn = new ADODB.Connection
set rsMain = new ADODB.Recordset

cn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\Website Projects\ExitCashFlow\logMaster\Logs.mdb;"

strSQL = "Select * From Main Where Username = '" & strQuery & "' and Domain = '" & strDomain & "'"

rsMain.CursorType = adOpenKeyset
rsMain.Open cn, strSQL
   
If rsMain.EOF Then
    rsMain.AddNew
       rsMain(UserName) = strQuery
End If

rsMain.Close
Set rsMain = Nothing


CHeers
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7066456
AngelIII is correct but to explain why:

The cn.Execute (strSQL) method returns a read-only recordset. Therefore it is not updatable. Using the .Open method on a recordset object allows you to specify the cursortype/location and locktype which you cannot do with the .Execute method. This is what angelIII shows. You can either set the recordset properties before opening the recordset as shown or using a single statement:

recordset.Open "SQL Statement",Connection,CursorType,LockType

The choice is yours.
0
 
LVL 3

Author Comment

by:Voltec
ID: 7068216
You actually reversed the connection and the SQL statement (the Open line should read rsMain.Open strSQL, cn) and that took me a few minutes to figure out why I was getting a '3001' error... but I fingered it out.  (=

Thanks for the Great info!

Matt
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

705 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

18 Experts available now in Live!

Get 1:1 Help Now