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

Write a macro to update a field on a form

Status
Not open for further replies.

jodiehbk

Instructor
Oct 12, 2007
2
I have a form on a table listing items available for hire. One field holds the number of each item available. I have a linked and synchronized form to manage the loans and another to manage the returns. I would like to write a macro attached to a command button on the loans form to decrease the number available by one, and a similar macro on the returns form to increase the number available by one. But I do not know the code to write in the macro. Can anyone help, please?

 
Write a query to perform the update.

Use openquery to run the query.

You may also want to use SetWarnings before and after running the query to suppress the messages.
 
Thanks, Lameid. I have done as you suggested BUT the query updates more than the one record. Do I need to set criteria in the update query to restrict the update to the item being hired, and what code do I write for this? Do I put the code in the criteria of the query or in the macro to run the query?

Jodi
 
You want to use criteria in the query...

You probably want to reference a control on the form for your criteria. In place of the value use the following syntax...

Forms!FormName!ControlName

You can also right click in the criteria and click build, and navigate through the panes at the bottom of the window to find the control or field you are looking for. Note in my example you can use a field name instead of a control name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top