Solved

Runtime error 3251 Current Recordset does not support updating

Posted on 2002-06-10
3
9,691 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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