Update two fields on Subform

detrie

Registered User.
Local time
Today, 01:52
Joined
Feb 9, 2006
Messages
113
I'm trying to update two fields (NewJF and NewDe) of all records in a subform based on two comboboxes (cmbSenior and cmbDe)
Works fine with one field but I cant seem to get the syntax right for the second one.

Code:
Private Sub UPdate_Click()
Dim rst As DAO.Recordset
   Set rst = Me.fSubClassification.Form.RecordsetClone
   rst.MoveFirst
   Do While Not (rst.BOF Or rst.EOF)
      rst.Edit
      rst![NewJF] = Me![cmbSenior],[NewDe] = Me.[cmbDe]
      rst.UPdate
      rst.MoveNext
   Loop
   Me.Requery
   Set rst = Nothing

End Sub
 
rst!NewJF = Me.cmbSenior
rst!NewDe = Me.cmbDe

or instead of RecordsetClone and looping:

CurrentDb.Execute "UPDATE tablename SET NewJF = '" & Me.cmbSenior & "', NewDe='" & Me.cmbDe & "' WHERE <some criteria here>"
 
Separate them:

rst![NewJF] = Me![cmbSenior]
rst![NewDe] = Me.[cmbDe]
 
In addition to the above answers, you should first test if there are records in the subform as in the case where you are in blank recordset, before issuing .Movefirst:

If rst.RecordCount <> 0 Then rst.MoveFirst


2nd you need not Requery the Form since you are directly editing the Form's recordset. Any changes you made are immediately reflected.
 

Users who are viewing this thread

Back
Top Bottom