Results 1 to 6 of 6

Thread: Filter records

  1. #1
    Join Date
    Oct 2004
    Location
    Edinburgh, Scotland
    Posts
    17

    Unanswered: Filter records

    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.
    Last edited by longIT; 10-11-04 at 09:55.

  2. #2
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    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:

    Code:
    Docmd.OpenForm "YourEditFormName",,,"[AdID]=" & Me!AdID,acFormEdit
    ghozy.

  3. #3
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    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.

    Simply type the following.

    DoCmd.OpenForm "myform",,,"[myvehicleid] = " & me.myvehicleid,,acDialog

    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.
    Rod

    fe_rod@hotmail.com

  4. #4
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    ghozy,

    You got there first - by seconds it seems! - but great minds think alike.

    longIT you added that final sentence about the control being called AdId after I started replying, didn't you!
    Last edited by Rod; 10-11-04 at 10:27.
    Rod

    fe_rod@hotmail.com

  5. #5
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    hehe, yours more detailed though.
    ghozy.

  6. #6
    Join Date
    Oct 2004
    Location
    Edinburgh, Scotland
    Posts
    17
    Thanks very much. That's just what I needed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •