Change values of filtered records

J

jeanulrich00

Hi

I have a continuous form (issue from a query)

Lets work with 3 fields "EmployeeName" "City" and "Projection"

Paul New-York 1
John New-York 1
Ted Chicago 1
Marc Toronto 1
Ed Toronto 1 and so on

On the form header I put a text field named "Taux"

What I want to do is simple but I don't succeed

I want to be able with a command button to change the value of the
filtered records

Example : If I make a filter on Toronto and if I put 2 in the text
field "Taux" after clicking the button I will obtain

Paul New-York 1
John New-York 1
Ted Chicago 1
Marc Toronto 2
Ed Toronto 2

Thanks for helping
 
K

Klatuu

You will need to create an Update query to update the field in the
underlying table.
It will need to be filtered exactly like your form is filtered.
It will need to have a parameter that refers to the control on your form for
the value you want to update the field to.
You can use the Execute method to do the update. You will also need to
requery your form after doing the update. You will be updating the table,
not the form, so to see the changes, the requery will be required.

This is only "air code", but it should give you the general idea:

Private Sub cmdUpdate_Click()
Dim strSQL As String
Dim lngPrimeKey As Long

'Create the Query SQL for the update
strSQL = "UPDATE MyTableName SET [Projection] = " & Me.Taux & _
"WHERE [City] = """ & Me.txtCity & """;"
'Update The table
Currentdb.Execute strSQL, dbFailOnError

'Save the Primary key value of the current form record to reposition the
form to the
'same record after the Requery
lngPrimeKey = Me.txtKeyFieldControl 'This is the control on your form
that has the value of the record's primary key field
'If the
field is not in a control, you can use the name of the field, but it does
have to be in the form's recordset
Me.Requery

'Reposition the current record back to what it was

With Me.RecordsetClone
.FindFirst "[PrimaryKeyFieldName] = " & lngPrimeKey 'Here you
must use the recordset field name, not the control name. Also, adjust the
syntax to suit the field type
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top