Update a field for all records in a form

  • Thread starter ondvirg via AccessMonster.com
  • Start date
O

ondvirg via AccessMonster.com

I have a form that has a textbox in the header that I populate with a value.
I'd like to have a command button that then updates a specific field for each
record displayed on the form with that value.

I've tried:

Me.FieldName = Me.Textbox

But this only updates the first record on the form. I know this is probably a
simple process, but I just can't get my head in it.

Thanks for any help
 
F

fredg

I have a form that has a textbox in the header that I populate with a value.
I'd like to have a command button that then updates a specific field for each
record displayed on the form with that value.

I've tried:

Me.FieldName = Me.Textbox

But this only updates the first record on the form. I know this is probably a
simple process, but I just can't get my head in it.

Thanks for any help

Is the value a Text value or a Number value or a Date value.
It does make a difference.

1) Forms don't actually 'contain' records. They simply display
records.
Tables contain records.

2) You can place code in a command button click event on the form that
will actually update ALL the records in the table:

CurrentDb.Execute "Update MyTable Set MyTable.[FieldName]
= " & Me!ControlName

The above assumes the [FieldName] datatype is a Number value.
Text and dates require a different syntax.

If the value is a Text datatype, then use:

CurrentDb.Execute "Update MyTable Set MyTable.[FieldName]
= """ & Me!ControlName & """"

If is is a Data datatype, then:

CurrentDb.Execute "Update MyTable Set MyTable.[FieldName]
= #" & Me!ControlName & "#"

Always indicate a field's datatype when asking for help.
Always back up your table data first before trying new code.
 
Top