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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with Update record on a subform

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Getting an error on this line
Me![HA3x5CardData subform]!PrintMe = True
Error is:
Update or CancelUpdate without Addnew or Edit

Where do I need to edit, the record source? or?
I want to check the PrintMe boxes on all records that show in the subform.

Code:
    Dim SyncCriteria As String
    Dim f As Form
    Dim rs As Recordset
    Dim a, TotalRecs As Integer
    Set rs = Me![HA3x5CardData subform].Form.RecordsetClone
    TotalRecs = rs.RecordCount
    For a = 1 To TotalRecs
        SyncCriteria = "[HA]='" & Me![HA3x5CardData subform].Form.[HA] & "'"
        rs.FindFirst SyncCriteria
        Me![HA3x5CardData subform].Form.Bookmark = rs.Bookmark
        
        [COLOR=red]Me![HA3x5CardData subform]!PrintMe = True[/color]
        rs.MoveNext
    Next
    Set rs = Nothing

DougP
 
Hi...

To update a field in a recordset

dim rs as recordset
set rs = (to a recordset)
rs.movefirst
Do until rs.EOF
rs.edit
rs("fieldname") = (Whatever)
rs.udate
rs.movenext
Loop

This is a generic construct for editing a recordset

You have a rs.movenext within a For-Next Loop,
this is not needed as the For-Next Loop will start at the begining of the recordset and loop until the end.

I just don't see where you are issueing a command to edit the recordset.

If the recordset is not being updated then won't your FindfFirst always find the same record?
 
DougP

You are using a DAO.Recordset which first needs the .Edit to fire and then change the data for the recordset. But since you have a many records I suggest you not to use a loop but rather
CurrentDB.Execute method for the appropriate SQL statment

strSQL = "UPDATE TableName " & _
"Set [PrintMe]= True " & _
"WHERE [HA]='" & Me![HA3x5CardData subform].Form.[HA] & "'"

CurrentDB.Execute strSQL
 
I want to update the form not open another recordset. Is there a way to do this?

DougP
 

Since the form is bound to a recordset, updating the recordset results in updating the form. That's what all three of us have been doing since the beginning of this post!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top