Code not working in Access 2007

Posted on 2011-10-05
Last Modified: 2012-06-27

I am having difficulty with getting code to work when i copy it from a forms control event procedure to another forms control event procedure, where the code doesnt recognise the controls.

e.g. form CameraDataEntry has a save button called cmdSaveRec. This button contain an event procedure on the click command. I copied this code to the cmdSave Rect button event procedure on the form ComputerDataEntry. I then amended the code to reference the controls on that form. For some reason, the code will not reference the controls and just doesnt work or i receive messages such "Method or data member not found", even though it does. Is some instances i am having to rename controls to get this work e.g. a control name Firstname which is on both forms, will not work in form ComputerDataEntry (the form i copied the code to), and thus i have had to change it to Firstname1.

Any ideas why this is happening? Is there a problem with access and bugs?

Kind regards
Question by:dgi001
    LVL 74

    Accepted Solution

    1. Always compile your code and run the compact/repair utility on a regular basis.
    2. Sometimes even though the code on an event is there, you still must go through the control to get it to work.

    You copy and paste this code to the form's module:
    Private sub YourButton_Click()
    msgbox "Button Clicked"
    end sub

    You sometimes still have to select the control in design view, open the property sheet, select the event (You may notice that the event is not there), then click the build button.

    3. Sometimes copying and pasting code to disparate locations will corrupt the form.
    Then you may have to delete, then re-insert the control, ...or in the worse case, you may have to rebuild the entire form from scratch.

    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    Also, make sure the DB is in a "Trusted Location".
    ...and for code on Reports, make sure the Report is opened in Print Preview explicitly, in order to run any code on any format events

    Author Closing Comment

    Hi Jeff

    Thanks for this. You have just confirmed what i experienced on 2 occasions where i had to rebuild the form from scratch. I will have to build the code from scratch to avoid this in the future.
    LVL 74

    Expert Comment

    by:Jeffrey Coachman
    Perhaps not, oddly enough, sometimes copying Code, Controls, Forms, Modules, ...etc from database to database works fine, ...sometimes not.

    I am sure there is some universal root cause for this, but again, if you compile/Compact regularly, this should not happen often...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now