Loop in an access macro

Copper Contributor

Can I do looping within an access macro?

7 Replies
can you do the same functionality using Query?

@arnel_gp   I probably could for most things I have tried.  I am still getting up to speed on Access programming with macros.  My question is, if I want to change some fields in a lot of records, doesn't a query just return records found, or it can append records or delete records.  But how do I get it  to update a few fields in all the records selected?

@michael99chronister 

First, we have to be clear about Macros. Unlike Excel which uses the term "macro" interchangeably with "VBA", Access has two distinct programming languages, Access macros, and VBA Functions and Subs.

 

Subs and Functions are much more useful and it's probably a good idea to move on to them as quickly as possible in the Access development environment. This is a good example of that.

 

Looping a recordset is a standard thing to do in VBA. I can't think of a way to do it in a Macro, although there might be some obscure method I'm not aware of.

 

So, the full answer is probably to just move on to VBA in Access and not spin your wheels with macros.

I thought that might be the case. It has been a long time since I did intense programming (like when there was no VBA but Basic only). Getting up to speed is a problem. ANy suggestions on good documents on how to get up to speed on VBA and especially formats for coding. An example would be I remember the expression component "LIKE" but don't remember parameters, sequence etc.

Thank you.
There are lots of good books on VBA, but mostly they would be older, probably. Not much recently.
YouTube has tons of videos, some of which might be useful.

Truthfully, there is some much to consider it's really hard to get traction without focusing on the need in front of you at the moment.
you can use an Update Query with Criteria of your selected records.
In most cases, an update query would probably be more efficient and faster, as well as less complicated to create. Check out the acronym "RBAR", which stands for "Row by Agonizing Row"
However, there are some scenarios where a looped recordset are required. It's the fussy details that make possible the proper selection of a technique.