Avatar of Russian_Lmg
Russian_LmgFlag for United States of America

asked on 

MS Access - How to cycle through records within a form to allow VBA update to occur for each record?

We have a particular form that reads from a table which stores start/due dates for production orders.  Those dates change as the quanitty of the production order changes, either longer or shorter.

As the quantity changes, this is captured and the dates will be altered based on the quantity changed.

I have already place the necessary VBA within the form so that when the record is opened, it checks the quantity and adjusts the date accordingly.  We do not do this in the update query as there is some work involved in getting the date format correct, as well as calculating the dates which will be updated.

What I am looking for is the next step, which is for the form to do this for each record, rather then the user needing to scroll through each records for the VBA to execute.  And when it gets to the end it is done, and the loop does not repeat.

Microsoft Access

Avatar of undefined
Last Comment
Rick_Rickards
ASKER CERTIFIED SOLUTION
Avatar of Rick_Rickards
Rick_Rickards
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Russian_Lmg
Russian_Lmg
Flag of United States of America image

ASKER

Yes, it does rely on the form being open.  This worked perfectly, but I did need to add an End With at the end of your code.
Avatar of Rick_Rickards
Rick_Rickards
Flag of United States of America image

Good call.  Glad it worked for you. :)
Private Sub cmdSample_Click()
    Dim rst As DAO.Recordset
    Set rst = Me.RecordsetClone
    With rst
        If .RecordCount Then
            .MoveFirst
            Do Until .EOF    'When the last record is reached the code stops
                Me.Bookmark = .Bookmark
                'Run your code here
                .MoveNext
            Loop
        End If
    End With
    rst.Close
    Set rst = Nothing
End Sub

Open in new window

Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo