Share via

Run code multiple times VBA

Anonymous
2012-10-07T10:50:41+00:00

I am using this to copy the current record and add new (simler records) to the table.

DoCmd.RunCommand acCmdSelectRecord

DoCmd.RunCommand acCmdCopy

DoCmd.RunCommand acCmdRecordsGoToNew

DoCmd.RunCommand acCmdSelectRecord

DoCmd.RunCommand acCmdPaste

I then have a code that alters certain fields.

Is it possible to run this multiple times.

For example if I have a text box and add 3 or 6 or 16 the code would run 3 or 6  o 16 times.

Thanks you

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2012-10-07T11:13:09+00:00

    As long as you don't copy anything else to the clipboard, the record will remain on the clipboard, so you might try something like this:

        Dim i As Long

        Dim n As Long

        DoCmd.RunCommand acCmdSelectRecord

        DoCmd.RunCommand acCmdCopy

        n = Val(Me.txtNumber)

        For i = 1 To n

            DoCmd.RunCommand acCmdRecordsGoToNew

            DoCmd.RunCommand acCmdSelectRecord

            DoCmd.RunCommand acCmdPaste

            ...

            ...

        Next i

    Was this answer helpful?

    0 comments No comments