Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9920
  • Last Modified:

Runtime error 3251 Current Recordset does not support updating

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
Voltec
Asked:
Voltec
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
TimCotteeCommented:
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
 
VoltecAuthor Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now