Results 1 to 9 of 9
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    change focus; disable control

    ...which lead me to a new problem...




    Private Sub cmdAccept_Click()
    ...
    With Forms![frmMainMenu].[cmdFixtureSchedulePrint]
    ...
    .setFocus
    End With
    Me.cmdAccept.Enabled = False '<--- this is the line that results in an error

    I thought that since I've just set focus to another control, it would be OK to disable this control (but maybe since I'm still in the event of that code, I can't)
    Would it make sense to move the code to disable cmdAccept to an event on the control I am moving focus to?
    and if so, behind which event should that be?

    or would there be a better approach?

    as always, thanks in advance,
    Mark

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

    ...Would it make sense to move the code to disable cmdAccept to an event on the control I am moving focus to...
    That depends; do you always want the Command Button named cmdAccept to be Disabled when you move to this other Control? If so, use the GotFocus event of that Control; if not so, post back.

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

    All posts/responses based on Access 2003/2007

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    What is the error message?

    Is the button "cmdAccept" on the form "frmMainMenu"?

    I tried your code (modified for my forms) and did not get an error.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I'm sure it is on the same form; Error #2164 "You cannot disable a control while it has focus."

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

    All posts/responses based on Access 2003/2007

  5. #5
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    I do always want the Command Button named cmdAccept to be Disabled when I move to the other Control cmdFixtureSchedulePrint

    cmdAccept is on a subform (unrelated to, but located on) the parent form which is where the other control is

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Just to make sure I understand,

    Button cmdFixtureSchedulePrint is on the main form?

    Button cmdAccept is on the subform?

  7. #7
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    change focus; disable control

    That is correct

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The main form has a focus and the sub-form has a focus. From the sub-form, if you set (change) the focus on the main form, you don't change which control on the sub-form has the focus.
    You have to change which control on the sub-form has the focus.

    Code:
    Private Sub cmdAccept_Click()
     ...
     With Forms![frmMainMenu].[cmdFixtureSchedulePrint]
            ...
            .setFocus  '<<=== only changes which control has the focus on the main form
     End With 
    
     Me.cmdAccept.Enabled = False '<--- this is the line that results in an error /Me.cmdAccept still has the focus
    Try this
    Code:
    Private Sub cmdAccept_Click()
      ...
      With Forms![frmMainMenu].[cmdFixtureSchedulePrint]
             ...
             .setFocus  '<<=== only changes which control has the focus on the main form, not the sub-form
      End With 
    
      Me.SomeOtherControl.Setfocus  , << a different control on the sub-form
      Me.cmdAccept.Enabled = False '<<== cmdAccept does not have focus, cmdAccept is disabled

  9. #9
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    makes total sense...
    BIG THANKS (yet again)

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

Similar Threads

  1. Control cannot receive focus
    By numberguy in forum Forms
    Replies: 2
    Last Post: 06-25-2012, 12:57 PM
  2. Focus in web browser control
    By bjornhe in forum Access
    Replies: 0
    Last Post: 10-27-2011, 05:10 AM
  3. Focus on Key Control
    By windwardmi in forum Access
    Replies: 1
    Last Post: 09-07-2011, 04:57 PM
  4. How to control a button when it has focus
    By shubhamgandhi in forum Programming
    Replies: 2
    Last Post: 07-28-2011, 03:18 PM
  5. Any change of focus on form Event?
    By trb5016 in forum Forms
    Replies: 1
    Last Post: 02-11-2011, 08:25 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