Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2010
    Posts
    10

    Enable button in the master form when clicking in the detail

    Hi,

    I would like to know how the best way to disable a button every time its focus is NOT in the detail and enable when a line in
    a grid in the detail is selected (clicked). The button is located in the master.

    I've done that but did't work:
    Private Sub cmd_LostFocus()
    Me.cmd.Enabled = False
    End Sub


    It gave me the error:
    Run-time error '2164'
    You can't disable a control while it has the focus

    I also tried to play with the Subform/Subreport events On Enter and On Exit as follow:

    Private Sub sub_Enter()
    Me.cmd.Enabled = True
    End Sub

    Private Sub sub_Exit()
    Me.cmd.Enabled = False
    End Sub


    It worked to enable and disable. However, when I am in the grid in the Subform and try to click in the bottom that is in the
    FormHeader, it raises the event Exit and, therefore, disable the botton. Any other solution?

    Is there a way for me to say in the sub_Exit like this?

    Private Sub sub_Exit()
    If NOT Me.cmd.Click Then
    Me.cmd.Enabled = False
    End if
    End Sub





    Thank you in advance.

    Regards.

  2. #2
    Join Date
    Aug 2010
    Posts
    10
    Does anyone knows more or less what could be done here?

    Thank you in advance.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Perhaps if you describe the function of this button on the MainForm someone would be able to offer a suggestion. Is your SubForm in Datasheet mode?

  4. #4
    Join Date
    Aug 2010
    Posts
    10
    Hi RuralGuy,

    Thanks for your message. However, I just want to enable or disable the buttom, whatever its function is. The selection type for the master is a Section and the detail is a grid inside a Subform/Subreport.

    Regards.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You can reference a MainForm with either the Me.Parent syntax or go through the Forms collection.

  6. #6
    Join Date
    Aug 2010
    Posts
    10
    I understood what you meant but don't know what is the syntax to do what I need.

    Following your suggestion, I would need something like:

    Private Sub sub_Exit()
    If NOT Me.Parent.cmd.Click Then 'Doesn't work
    Me.cmd.Enabled = False
    End if
    End Sub

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm not sure what you meant when you said:
    Quote Originally Posted by DistillingAccess View Post
    I would like to know how the best way to disable a button every time its focus is NOT in the detail

  8. #8
    Join Date
    Aug 2010
    Posts
    10
    Let's pretend I have two forms, A and B. In the form A I have a bottom. I only want to enable the bottom when I am with the cursor in the form B. If I leave it -- the form B--, the bottom in the form A should be disabled.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you should be able to disable the Command Button in the GotFocus event of the SubForm.

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

Similar Threads

  1. Replies: 1
    Last Post: 07-27-2010, 08:02 AM
  2. Apend Query for master and sub form
    By lupis in forum Forms
    Replies: 4
    Last Post: 05-28-2010, 06:27 PM
  3. could not enable autocorrect
    By easbrandel in forum Access
    Replies: 0
    Last Post: 04-15-2010, 07:10 AM
  4. Replies: 3
    Last Post: 02-19-2010, 04:19 PM
  5. Replies: 5
    Last Post: 02-10-2010, 12:27 AM

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