I have a form called 'Vehicles for sale' where users can look at all records one at a time. There is also a form called 'Edit Vehicles for form sale' which is based on this form. There is a button on the 'Vehicles for sale' called edit record.
What I want is when the user clicks on the edit button the 'Edit Vehicles for form sale' form opens with the selected record from the 'Vehicles for sale' form.
I know I probably need some kind of filter, but I've never used one before, so I could do with a little help.
It may be useful to know that each record had an Advertisement ID called AdID.
I think there is a wizard to do that. when you add a button with wizard oprion is on, you can choose to open a new form for editing a record with a filter based on your main form.
anyway you can also do it with adding a parameter to docmd.openform. something like:
Probably the most convenient way to do what you want is to use the OpenForm method of the DoCmd object. This will have to be written in the code window, don't associate a macro with your edit button.
So in the form's design view select the edit button and then select the event tab in the properties dialog. Click in the On Click line. Delete anything showing in this line and then click on the elipses at the right-hand end (the button with three full stops). Finally select Code Builder. This takes you to the VBA code window and opens a procedure for you.
Let me explain the arguments. myform is your edit form name, it must be enclosed between quotation marks.
The commas following delineate two missing optional arguments.
For the next argument you are forming a string to be used as a WHERE clause (without the WHERE keyword). My example assumes there is a control on the edit form named myvehicleid that contains the unique reference to the vehicle and there is also a control on the present form (me) that holds this value. Further this example assumes the vehicle id is numeric. If it is alpha numeric then the argument needs to be written as
"[myvehicleid] = '" & me.myvehicleid & "'"
Finally after one more missing argument I have specified that the edit form must open as a dialog, that is it is modal and the user cannot move away from it without closing it.