Results 1 to 9 of 9
  1. #1
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24

    Unhappy Disabling A Button

    I know I am missing something simple here... but I cannot figure it out. The below code is not disabling the button:

    Forms!FrmMain.BtnAdmin.Enabled = False



    What am I doing wrong?!

  2. #2
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    Without knowing anything else about the database there are 2 possibilties:

    1. Typo. You have mispelled the name of the form or button.

    2. Event. The placement of the code is not occurring when you want it to.

    What is the exact name of the form and button?

    Where did you place the VB code?

    Also, if the command to disable the button is on the same form as the button then you should be able to just type me.BtnAdmin.Enabled = False .

    *****
    Ok I just made a quick form and button, named the button BtnAdmin and in the OnLoad event of the form used me.BtnAdmin.Enabled = False and it did work.
    Last edited by michaeljohnh; 10-05-2010 at 01:16 PM. Reason: additional comments

  3. #3
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    1. VB is recognizing the form and button name (Changed case of character and VB corrected).
    2. I am placing the code after:

    DoCmd.OpenForm "FrmMain"
    DoCmd.Close acForm, "FrmLogOn"

    The button name is "BtnAdmin"

  4. #4
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    In the OnLoad event of FrmMain enter the following:

    me.BtnAdmin.Enabled = False

  5. #5
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    Sorry, I should have clarified that this code is working through multiple cases. Each case disables different buttons on the FrmMain form based on user rights in the FrmLogOn form.

    Case 1

    DoCmd.OpenForm "frmMain"
    DoCmd.Close acForm, "frmLogOn"

    Case 2

    DoCmd.OpenForm "frmMain"
    DoCmd.Close acForm, "frmLogOn"

    etc...

  6. #6
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    So if the VB code is on FrmLogOn and the code to disable the button follows the code to close FrmLogOn, then the reason for it not working seems to be that the code to disable the button isnt getting executed because the form it is on has been closed.

  7. #7
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    Moving the code has had no effect

  8. #8
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    The only other option I can think of is moving the entire Select/Case sub to the OnLoad event of the frmMain. Since the login info is being stored somewhere, it should be easy enough to check it during the OnLoad event rather than on the frmLogOn. With one database I made, I left the login form open but repositioned it behind the other forms so I could pull from the username field for exactly this type of check. Although that was a very low security db, so logging in was more to apply user preferences than a security measure.

    If that doesnt work, someone else will hopefully be able to help you, I will be heading home soon.

  9. #9
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    I like the idea of leaving the login form open and will try that. Thanks!

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

Similar Threads

  1. Disabling Design View
    By DonnyArt in forum Access
    Replies: 1
    Last Post: 06-29-2010, 08:08 AM
  2. Disabling Text Box for Certain Users
    By sky in forum Forms
    Replies: 1
    Last Post: 12-31-2009, 09:06 PM
  3. Replies: 0
    Last Post: 10-12-2009, 08:26 AM
  4. Replies: 5
    Last Post: 08-06-2009, 11:47 PM
  5. Disabling shift for design view
    By geek in forum Access
    Replies: 1
    Last Post: 12-09-2005, 11:38 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