Results 1 to 4 of 4
  1. #1
    aaron47 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    11

    disabling an enabled button that has been clicked.

    I am working with a form in Access to submit a report that reads data from a linked table. On the form, I have a start date, an end date, a 'preview report' button, a 'reset screen' button and a 'publish report to Microsoft Word' button. I have it set up so that the first button is enabled and the other two buttons are disabled. After a user enters the start and end dates and the user presses the 'preview report' button to create the report, I want the code to disable the 'preview report and enable the other two buttons but this doesn't work inside the code for the 'preview report' button because of control focus. How can I change the control focus inside the code?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    before you do anything with opening the report in the ON CLICK event of the 'preview report button' have something like

    me.SecondButton.enabled = true (reset screen button)
    me.ThirdButton.enabled = true (publish report button)
    you *may* need this line
    docmd.gotocontrol me.secondbutton
    then follow it up with
    me.FirstButton.enabled = false (print preview button)

    then go on about opening your report as normal

  3. #3
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    aaron47 -

    Along the same lines as rpeare indicated, personally, I would begin with...

    In the form OnOpen event:
    Me![Button1].enabled = False
    Me![Button2].enabled = False
    Me![Button3].enabled = False

    Then, in the BeforeUpdate event of the end date control, after any other validation code, something like:

    If IsDate(Me![EndDate])=True And IsDate(Me![StartDate])=True then
    Me![Button1].enabled = True
    Me![Button2].enabled = False
    Me![Button3].enabled = False
    end if

    Thereafter, set the report's modal property to Yes and eliminate the reports min/max buttons.

    Then in the OnGotFocus or OnLoad or OnOpen event of the report (provided the form is still open):
    [Forms]![FormName]![Button1].enabled = False

    Then in the OnDeactivate event of the report (provided the form is still open):

    [Forms]![FormName]![Button2].enabled = True
    [Forms]![FormName]![Button3].enabled = True

    and see if that produces the desired results.

    All the best,

    Jim

  4. #4
    aaron47 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    11
    Thank you for your suggestions. I tried using the gotocontrol method suggested by rpeare but that gave me an error message. However, the description of gotocontrol pointed me to a setfocus method which gave me the desired results.

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

Similar Threads

  1. Enabled = False
    By Juan4412 in forum Forms
    Replies: 2
    Last Post: 04-19-2011, 06:05 PM
  2. Disabling A Button
    By cksm4 in forum Programming
    Replies: 8
    Last Post: 10-05-2010, 02:07 PM
  3. How to pass what was clicked to module?
    By nichojo in forum Modules
    Replies: 11
    Last Post: 07-22-2010, 08:27 AM
  4. Replies: 4
    Last Post: 09-10-2009, 03:09 AM
  5. Replies: 5
    Last Post: 08-06-2009, 11:47 PM

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