Forum Discussion

Tom_M_1969's avatar
Tom_M_1969
Copper Contributor
Nov 23, 2021

Form button has to be recreated every time Access closes and is reopened

I have a frustrating problem with a data entry form I created in my Access database. I created a button on the form (using one of the Form Design controls) that duplicates the current record every time it is clicked. It worked fine for a long time, but one day it stopped working. When I click it, the gray bar on the left side of my Form window turns black, and nothing else happens.

 

If I delete the button and recreate it, it works fine until I close and reopen Access. Then it stops working again. So I have to recreate the button from scratch every time I use the form!

 

I've included a screen shot of the embedded code that makes the button work. In the Event properties for the button, On Click is set to "Embedded Macro." I didn't create this macro, I just chose a function that was already available in Access.

 

Any help would be greatly appreciated! Thanks.

  • George_Hepworth's avatar
    George_Hepworth
    Silver Contributor
    The last line or lines of the macro are not visible in the screenshot. The part that is visible doesn't reveal any obvious problems.

    Try setting the macro to run single step and see if you can identify the line which is creating the problem.
  • arnel_gp's avatar
    arnel_gp
    Steel Contributor
    are you limited to macro only.
    you can do it using VBA:

    private button1_Click()
    Me![anyTextboxOnYourForm].SetFocus
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdPasteAppend
    end sub
  • BrianWS1O's avatar
    BrianWS1O
    Brass Contributor
    My opinion: NEVER EVER USE MACROS, they are an invention of the Devil! Write VBA code, which can be easily edited, modified, debugged, error trapped, etc. You can even save working VBA code into text files so they don't disappear if your database ever gets corrupted or deleted.

    If you have a goofy form in your database, try creating a new empty ACCDB file and importing all the forms, tables, queries, code, etc, into it. Sometimes MS Access files get corrupted (ok, they get corrupted a lot), and occasional the only fix is to start with a whole new fresh container. And make backups all the time! I do it several times a day when I'm in heavy development mode so i don't lose my work if Access goes crazy. Which it will do.

Resources