Query button in form

A

Andy

I have a form with two sets of data in, running from one table. I would like
a button that would give the user the ability to update dataset 2 with the
information in dataset 1 on an individual record basis for each page on the
form

Basing this button on a simple update query, updates all dataset in the
ENTIRE table. Is there someway I can build into the query that it only
updates the dataset fields for the one record that it is looking at?

Perhaps more a query question, but I got no joy from a post.

Thanks
 
J

Jeff L

Andy,
You need to have a field that identifies which record you want to
update, like ID. This field is typically your primary key for the
table. When you run your query, you want to update the record that
matches the ID field on your form.

Docmd.RunSQL "Update YourTable " & _
"Set YourField = SomeValue " & _
"Where ID = " & Me.ID

Hope that helps!
 
A

Andy

y Yeah, I knew that it would have something to do wiht updating the
individual record, but....

as the user will be viewing a form, will the query automatically select the
record relating to say Primary key = 6 that is visible in the form without
the user having to input the primary key from a promt? if the user then looks
at record with primary Key 6 and they run the query, will this then just
update record 6?

Onl yjust beginning to use and understand SQL, and hate to ask...

Could you give me some SQL to test, if it is TABLE A, with FIELD 2 to update
with FIELD 1 and the Primary Key has the unique identifier?

Thanks in advance....
 
J

Jeff L

If you are viewing a form that has the primary key as part of its
Record Source, then when you run your query you would just refer to the
Primary Key field. Some SQL to test as you requested:

Docmd.RunSql "Update TableA " & _
"Set Field2 = " & Me.Field1 & _
" Where ID = " & Me.ID

ID in the example is the primary key
 

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