Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Recordset Not working

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
0
0
GB
I am trying to update a recordset with the following code but get the error: Operation is not supported for this type of object. This happens on the find first bit

Code:
Dim rs As DAO.Recordset
Dim db As DAO.Database

Set db = CurrentDb
Set rs = db.OpenRecordset("tblEngagements")
DoCmd.Save
With rs
.Edit
SrchCrit = CStr(Me!frmEngagementQuickAddSub!EngagementID)
rs.FindFirst "EngagementID = " & SrchCrit
rs!SchoolID = Me.SchoolID
rs!BookingYearID = Year(Date)
rs!EngagementNumber = "1"
rs!HowHeardID = Me.HowHeardID
.Update
End With
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
 


Try:
Code:
[blue]   Dim rs As DAO.Recordset, db As DAO.Database, [purple][b]SrchCrit[/b][/purple]

   Set db = CurrentDb
   Set rs = db.OpenRecordset("tblEngagements")
   [purple][b]DoCmd.RunCommand acCmdSaveRecord[/b][/purple]
   
   With rs
      .Edit
      SrchCrit = CStr([purple][b][frmEngagementQuickAddSub].Form[/b][/purple]!EngagementID)
      rs.FindFirst "EngagementID = [purple][b]'"[/b][/purple] & SrchCrit & [purple][b]"'"[/b][/purple]
      rs!SchoolID = Me.SchoolID
      rs!BookingYearID = Year(Date)
      rs!EngagementNumber = "1"
      rs!HowHeardID = Me.HowHeardID
      .Update
   End With
   
   Set rs = Nothing
   Set db = Nothing[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I'd FindFirst BEFORE Edit ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I still get the same error message with your modified code.

Any other ideas?
 
Did you Edit AFTER FindFirst ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yeah I then changed my code to:

Code:
Dim rs As DAO.Recordset, db As DAO.Database, SrchCrit

   Set db = CurrentDb
   Set rs = db.OpenRecordset("tblEngagements")
   DoCmd.RunCommand acCmdSaveRecord
   
   With rs
      SrchCrit = CStr([frmEngagementQuickAddSub].Form!EngagementID)
      rs.FindFirst "EngagementID = '" & SrchCrit & "'"
      .Edit
rs!SchoolID = Me.SchoolID
      rs!BookingYearID = Year(Date)
      rs!EngagementNumber = "1"
      rs!HowHeardID = Me.HowHeardID
      .Update
   End With
   
   Set rs = Nothing
   Set db = Nothing

It stopped at the find first again
 

Not played with Access in a while, plus I have a memory like a sieve, but is the reference to rs within the "With" block necessary ?

Code:
Dim rs As DAO.Recordset, db As DAO.Database, SrchCrit

   Set db = CurrentDb
   Set rs = db.OpenRecordset("tblEngagements")
   DoCmd.RunCommand acCmdSaveRecord
   
   With rs
      SrchCrit = CStr([frmEngagementQuickAddSub].Form!EngagementID)
      .FindFirst "EngagementID = '" & SrchCrit & "'"
      .Edit
      !SchoolID = Me.SchoolID
      !BookingYearID = Year(Date)
      !EngagementNumber = "1"
      !HowHeardID = Me.HowHeardID
      .Update
   End With
   
   Set rs = Nothing
   Set db = Nothing
 
What happens if you replace this:
Set rs = db.OpenRecordset("tblEngagements")
with this:
Set rs = db.OpenRecordset("SELECT * FROM tblEngagements")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ok now I get a data type mismatch error
 
Replace this:
.FindFirst "EngagementID = '" & SrchCrit & "'"
with this:
.FindFirst "EngagementID = " & SrchCrit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Learn how to debug/troubleshoot faq705-7148. I'm not sure why you are opening a recordset of the entire table when you want to work with only a single or subset of records. I would include the search criteria as a where clause in the OpenRecordset

Code:
Dim strSQL As String
strSQL = "SELECT field1, field2, field3,... " & _
   "FROM tblEngagements " & _
   "WHERE EngagementID = ..."
'you can now debug your strSQL
Set rs = db.OpenRecordset(strSQL)
With rs
    If Not .eof Then
    '....etc

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top