Connecting Tech Pros Worldwide Forums | Help | Site Map

Current Recrdset does not support updating

Familiar Sight
 
Join Date: Nov 2006
Posts: 134
#1: Dec 23 '06
I got this Run-time error 3251

Current Recrdset does not support updating. This may be limation of the provider, or of the selected locktype.


Dim red1 As New ADODB.Recordset
Dim strmess As String

Set cnp = CurrentProject.Connection
strmess = "SELECT * from tblinvoicelines WHERE invoice=" & newInvo
Set red1 = cnp.Execute(strmess)

If Not red1.EOF Then
red1.MoveFirst
Do While Not red1.EOF
If red1!Invoice = newInvo Then
red1.Fields("amount") = Round(red1!Qty_Order * red1!Sell_price, 2)
red1.Update

End If
red1.MoveNext
Loop

End If

How can I resolve this, why MS Access does allow this simple updating ?

sashi's Avatar
Expert
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,630
#2: Dec 23 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by jamesnkk

I got this Run-time error 3251

Current Recrdset does not support updating. This may be limation of the provider, or of the selected locktype.


Dim red1 As New ADODB.Recordset
Dim strmess As String

Set cnp = CurrentProject.Connection
strmess = "SELECT * from tblinvoicelines WHERE invoice=" & newInvo
Set red1 = cnp.Execute(strmess)

If Not red1.EOF Then
red1.MoveFirst
Do While Not red1.EOF
If red1!Invoice = newInvo Then
red1.Fields("amount") = Round(red1!Qty_Order * red1!Sell_price, 2)
red1.Update

End If
red1.MoveNext
Loop

End If

How can I resolve this, why MS Access does allow this simple updating ?

Hi there,

Kindly refer to below modified code segment, hope it helps. Good luck & Take care.

Expand|Select|Wrap|Line Numbers
  1.   strmess = ""
  2.   strmess = "SELECT * from tblinvoicelines  WHERE invoice=" & newInvo
  3.   red1.Open strmess, CurrentProject.Connection, _
  4.             adOpenKeyset, adLockOptimistic
  5.  
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,216
#3: Dec 23 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by jamesnkk

I got this Run-time error 3251

Current Recrdset does not support updating. This may be limation of the provider, or of the selected locktype.


Dim red1 As New ADODB.Recordset
Dim strmess As String

Set cnp = CurrentProject.Connection
strmess = "SELECT * from tblinvoicelines WHERE invoice=" & newInvo
Set red1 = cnp.Execute(strmess)

If Not red1.EOF Then
red1.MoveFirst
Do While Not red1.EOF
If red1!Invoice = newInvo Then
red1.Fields("amount") = Round(red1!Qty_Order * red1!Sell_price, 2)
red1.Update

End If
red1.MoveNext
Loop

End If

How can I resolve this, why MS Access does allow this simple updating ?

If I am not mistaken, and unless otherwise specified, isn't the Default ADO
Recordset Read Only..
sashi's Avatar
Expert
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,630
#4: Dec 24 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by ADezii

If I am not mistaken, and unless otherwise specified, isn't the Default ADO
Recordset Read Only..

Hi there,

Yes, the default locktype is set to adLockReadOnly. This property is set to read/write on a closed recordset and read-only on an open recordset. Take care.
Familiar Sight
 
Join Date: Nov 2006
Posts: 134
#5: Dec 24 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by sashi

Hi there,

Kindly refer to below modified code segment, hope it helps. Good luck & Take care.

Expand|Select|Wrap|Line Numbers
  1.   strmess = ""
  2.   strmess = "SELECT * from tblinvoicelines  WHERE invoice=" & newInvo
  3.   red1.Open strmess, CurrentProject.Connection, _
  4.             adOpenKeyset, adLockOptimistic
  5.  

I copy your statement, I got an error message - Run time error - 3705
Operation is not allowed when the object is open.
Lives Here
 
Join Date: Oct 2006
Posts: 1,626
#6: Dec 24 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by jamesnkk

I copy your statement, I got an error message - Run time error - 3705
Operation is not allowed when the object is open.

that is because you have already opened the recordset earlier in your code.
insert this just before the code that you posted above:
red1.Close
Lives Here
 
Join Date: Oct 2006
Posts: 1,626
#7: Dec 24 '06

re: Current Recrdset does not support updating


BTW it is much better to explicitly initialize your recordset like this:
Expand|Select|Wrap|Line Numbers
  1. Dim red1 As ADODB.Recordset
  2. Set red1 = New ADODB.Recordset
If you do it this way:
Expand|Select|Wrap|Line Numbers
  1. Dim red1 As New ADODB.Recordset
each time you use red1 it will be checked to see if has been initialized which is inefficient
Familiar Sight
 
Join Date: Nov 2006
Posts: 134
#8: Dec 24 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by willakawill

BTW it is much better to explicitly initialize your recordset like this:

Expand|Select|Wrap|Line Numbers
  1. Dim red1 As ADODB.Recordset
  2. Set red1 = New ADODB.Recordset
If you do it this way:
Expand|Select|Wrap|Line Numbers
  1. Dim red1 As New ADODB.Recordset
each time you use red1 it will be checked to see if has been initialized which is inefficient

Wow !, Thank so much for your coding, I got it work now !, and Thank so Much for the explanation. Also Thank Sashi, Thank God, I came to the right forum.
sashi's Avatar
Expert
 
Join Date: Jun 2006
Location: Seremban, Malaysia
Posts: 1,630
#9: Dec 26 '06

re: Current Recrdset does not support updating


Quote:

Originally Posted by jamesnkk

Wow !, Thank so much for your coding, I got it work now !, and Thank so Much for the explanation. Also Thank Sashi, Thank God, I came to the right forum.

Hi there,

Good luck & Take care.
Reply