Access 2007 Use SetValue macro to add date to multiple records RRS feed

  • Question

  • I have a form where the user first selects an ID in the main form, then all the measurement records for that ID appear in a subform. I have a command button set to run a SetValue macro to apply the date entered in a text box on the main form to the Date column in my subform. Currently, the macro only updates the record that is selected in the subform. Is there a way I can apply this macro to all records in the subform with an ID that matches the selected ID in the main form?

    I am new to Forms and not entirely comfortable using VBA. I tried setting a module to run an IF statement but I don't think my syntax was correct:

    IF [Forms]![MainForm]![SubForm]![ID] = [Forms]![MainForm]![ID] THEN DoCmd.RunMacro(mcrSetDate)

    • Edited by bb1028 Friday, December 23, 2016 10:13 PM
    Friday, December 23, 2016 10:12 PM

All replies

  • Hi,

    You might be able to set the focus to the subform and then use the GoToRecord action to move through each one and then set the date. However, if all records are supposed to have the same date, why not just store the date on the main form.

    Just a thought...

    Saturday, December 24, 2016 1:09 AM
  • Hi bb1028,

    suggestion given by .theDBguy can solve your issue.

    below are the references that may help you.


    SetFocus Method [Access 2003 VBA Language Reference]

    DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7

    DoCmd.GoToRecord Method (Access)



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 26, 2016 2:01 AM