0
votes

I have a large MS Access 2013 application, and while adding some new logic I've come come upon an obstacle that no amount Googling has allowed me to overcome.

When I run the following code I get a

runtime error 3021: No current record.

error message when executing the last statement:

Docmd.Close acForm,"Picking"
DoCmd.DeleteObject acForm, "Picking"
DoCmd.CopyObject, "Picking", acForm, "Picking On Tablet"

The two forms listed in the code both exist and are proper. The first form (Picking) is being deleted properly in the 2nd statement. (The name has been removed from the list of form objects showing in the nav pane.)

My guess is that I need to somehow refresh the objects list before I run the 3rd statement but can't figure out how to do that. As a lark, I did try DoCmd.RefreshRecord since runtime error 3021 says "no current record" but of course this didn't work.

Am I on the right track? Any other ideas? I'm completely stumped.

2
More likely, the message is related to something going on in the form where you call that code. Will it run if called from the Immediate window? - Gustav
I agree with Gustav, I can't find a single reference to this error being caused by DoCmd.CopyObject anywhere on the internet and I have a black-belt in Googling. - Newd

2 Answers

0
votes

You don't mention where your code is located (it can't be in form 'Picking'), but I got the following to work in a Module. You can delete whatever 'RefreshDatabaseWindow' commands you want until you find the culprit...

Option Compare Database
Option Explicit

Sub Do_Something_With_Forms()

RefreshDatabaseWindow
DoCmd.Close acForm, "Picking"
RefreshDatabaseWindow
DoCmd.DeleteObject acForm, "Picking"
RefreshDatabaseWindow
DoCmd.CopyObject , "Picking", acForm, "Picking On Tablet"
RefreshDatabaseWindow

End Sub
0
votes

Thanks to all for your help. The answers all provided perspective. Based on your feedback I decided to check my work elsewhere. Sure enough, code elsewhere was the source of the issue.

It's times like this when I wish Access would provide stack visibility. What I discovered by hitting F8 some 50-75 times was that I was erroneously executing code to re-establish ODBC links for all my tables, while at the same time essentially, the code in question was manipulating the picking form.

The picking form links to two of the tables and this most likely caused my issue.

After correcting my logic error now the code works fine (yes, it does run in a separate module).