Results 1 to 6 of 6
  1. #1
    Seamus59 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    34

    Question OnClick event doesn't fire unless I switch to design view back to form view

    I have a form I create programatically, and it has "Save" and "Discard" buttons. On a previous job it works pefectly, but in my current project it does not.



    The buttons and supporting OnClick code seem fine but when my progam opens the form, the buttons don't work unless I change from form view into either Layout or Design, then change back to Form View, then they work perfectly. Perhaps someone has had this problem before and knows if there is a way to get Access to "reset" whatever it needs when the form loads.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why do you create form programmatically?

    At a minimum, you should post the code for analysis. If you want provide db, follow instructions at bottom of my post. Identify object involved.

    What do you mean by 'previous job' - a different db file?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by Seamus59 View Post

    ...On a previous job it works pefectly, but in my current project it does not...

    ...the buttons don't work unless I change from form view into either Layout or Design, then change back to Form View, then they work ...
    From v2007 forward Access files need to be in a Folder that has been declared as 'Trusted.' If this hasn't been done, code will run when going from Design View to Form View, but not when the Form is independently opened in Form View. Perhaps this was done in your previous project but not in this one?

    To "Trust" your folder, click:

    • Office Button (top left)
    • Access Options (bottom of dialog)
    • Trust Center (left)
    • Trust Center Settings (button)
    • Trusted Locations (left)
    • Add new location (button)

    The code works, when going from Design View to Form View, because the Access security is only invoked when opening the Form directly, i.e. clicking on the Form in the Navigation Pane.

    Like June7, I'm curious/concerned about your statement "I have a form I create programatically." This type of thing is usually a very bad idea.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Seamus59 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    34

    Perplexed but hopeful

    Thanks for your suggestion. It was a good one, but the trust settings are identical between the working and not working databases.
    A little explanation:

    I designed a database that creates a form programatically, which allows a supervisor to decide which questions should appear on a form. It works wonderfully. Then I made a duplicate of that database to modify for a different application that needs the same flexibility. It works almost as good as it's parent, except when the form opens, the buttons "Discard" and "Save", while clickable, do not work. I can click one and the other and they get focus, but the onclick event never occurs. I simply right click, change to "Layout" or "Design" view and immediately back to form view and they work!?!

    Now that I'm writing this, I'm going to try the "On Got Focus" event and see if that fixes it..

    I'll Keep you informed!

  5. #5
    Seamus59 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    34
    Well, "GotFocus" doesn't work either, although the command button clearly has focus...

  6. #6
    Seamus59 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2013
    Posts
    34
    Wow, figured it out...

    I (previously) define all the controls on the form, save it, then defined the module...Well it worked in the previous database (I don't know why) but not on this one. But when I move my:

    DoCmd.Close acForm, frmNew, acSaveYes
    DoCmd.OpenForm frmNew, acNormal, , , acFormEdit, acIcon, intTargetID

    to AFTER module definition, it works! YAY!

    Now I have changed them both to the (more logical) "Finish, Then Save!" Duh!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. remove design view and layout view on right click
    By sdel_nevo in forum Programming
    Replies: 2
    Last Post: 07-11-2013, 01:00 AM
  2. Replies: 2
    Last Post: 06-26-2013, 12:13 PM
  3. Replies: 8
    Last Post: 04-29-2013, 11:23 AM
  4. Replies: 16
    Last Post: 09-12-2012, 08:39 AM
  5. Replies: 2
    Last Post: 05-23-2012, 01:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums