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

Set Multiple Values in Subform

Status
Not open for further replies.

kenman

Programmer
Dec 21, 2000
12
0
0
US
I have a subform with 10 fields. The User enters multiple records (lets say 5 in this case) into this subform. After entering these records, they can choose to save the records as part of a set. I have one field called [SaveName] in the subreport. If the user enters a valid Save Name (One that does not already exist), and hits the save button, I would like to just go to the Subform and set all 5 records value of [SaveName] to the chosen name. I know the syntax for setting the current row is
SubFormWithRecords.Form![SaveName] = "Save Name 1"

Is there an easy way to set the value of [SaveName] for all of the records visible in the form? Do I have to scroll through them and set each one individually? If yes, how do I get a handle on each record?

Basically, I am looking for the equivalent of the following

for i = 1 to maxRecordsInForm
SubFormWithRecords.Form![SaveName]. = "Save Name 1"
next

Thanks in advance,

Ken
 
You shouldn´t change values on the form itself, but in the underlying recordset. Try something like:

Private Sub cmdButton1_Click()

Dim RS As Recordset

Set RS = CurrentDb.OpenRecordset(Me.RecordSource)
RS.MoveFirst
Do Until RS.EOF
RS.Edit
RS!fieldname = txt1.Value
RS.Update
RS.MoveNext
Loop
Me.Requery

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top