Results 1 to 8 of 8
  1. #1
    FredLanger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    4

    How to run macro on filtered dataset

    I have a form that lets you choose and/or type in search criteria in the header,


    then returns all the matching records in a list view below. I want to have a
    button in the header that, when clicked, runs a specific macro on each record in
    the filtered list.

    I am using Access 2010.

    Thank you!
    Fred

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    What do you want to do to each record?

    Possibly can use the RecordsetClone method. I don't know if macro can handle RecordsetClone, I use only VBA.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    FredLanger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    4
    Quote Originally Posted by June7 View Post
    What do you want to do to each record?

    Possibly can use the RecordsetClone method. I don't know if macro can handle RecordsetClone, I use only VBA.
    The macro runs a sequence of formulas to update several currency fields. I wouldn't want the update to occur on all records, only a select group at any given time. The main purpose for this is that we are tweaking some of the formulas and only want the results to affect unsold items in inventory - so I filter down to Unsold items on the list form, then I want to hit a Recalculate button and have the macro run the formulas on just those Unsold items records.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Provide code or the project for analysis.

    Are you running UPDATE queries in the macro?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    FredLanger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    4
    The form on which I would like to run the macro is based on this form from Allen Browne. Do you need to see the macro as well?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Okay, so you do a filter of form's recordset and want to run code that will update fields of each record in that filtered set. I don't see macro doing this, VBA could. As suggested, the RecordsetClone is possible approach. Here is some starter info http://msdn.microsoft.com/en-us/libr...ffice.12).aspx
    and
    http://bytes.com/topic/access/answer...recordsetclone
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    FredLanger is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    4
    Quote Originally Posted by June7 View Post
    Okay, so you do a filter of form's recordset and want to run code that will update fields of each record in that filtered set. I don't see macro doing this, VBA could. As suggested, the RecordsetClone is possible approach. Here is some starter info http://msdn.microsoft.com/en-us/libr...ffice.12).aspx
    and
    http://bytes.com/topic/access/answer...recordsetclone
    Sorry - I have been elsewhere and just landed back on this project. I looked at the RecordSetClone and don't really grasp how to apply it here.

    What if my need was simplified a bit? What I really need to do is Click a button that runs a macro or VBA code that checks the first record in the Inventory table: if Sold is true it moves on to the next record without running the Calculations macro. If Sold is false, it runs the Calculations macro, then moves to the next record.

    Today I am tweaking the formulas in the Calculations macro and when finished I will have to manually run the Calculations macro on each of several hundred records in the DB - one at a time. Ugh. It seems like there must be a "simple" solution :-)

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,952
    Perhaps an UPDATE query could do that. Apply filter criteria for records where Sold = False.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dataset returning different results
    By Juan23 in forum Programming
    Replies: 8
    Last Post: 09-16-2011, 03:03 PM
  2. Help filtering a dirty dataset
    By za20001 in forum Queries
    Replies: 0
    Last Post: 04-16-2011, 10:51 AM
  3. Replies: 0
    Last Post: 01-12-2011, 12:43 PM
  4. Filtered Report
    By Desstro in forum Reports
    Replies: 3
    Last Post: 06-18-2010, 09:09 AM
  5. Replies: 1
    Last Post: 03-09-2010, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums