Results 1 to 3 of 3
  1. #1
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22

    How to control a button when it has focus

    I'm trying to disable a button when it is clicked:

    Code:
    Private Sub submitButton_Click()
    
        Me.submitButton.Enabled = False
        If dataPath = "" Or skuPath = "" Then
            MsgBox "Please enter spreadsheet locations."
        Else
    
            Call importExcelData(dataPath, "data")
            Call importExcelData(skuPath, "skus")
    
            If validate = True Then
                Call generateReports
            End If
        End If
    
    End Sub
    I'm getting a runtime error: "You can't disable a control while it has the focus". Do you know a way around this?

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Move focus to another control first (maybe a textbox that is layered behind the button and has no other purpose, textbox TabStop property set to No) then code in that control's GotFocus event has code to disable the button.
    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
    shubhamgandhi is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    22
    Hey thanks that worked!

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

Similar Threads

  1. Replies: 0
    Last Post: 04-12-2011, 10:37 AM
  2. Replies: 0
    Last Post: 04-11-2011, 01:39 PM
  3. User focus control in AfterUpdate event
    By nosliwmada@gmailcom in forum Programming
    Replies: 3
    Last Post: 12-20-2010, 12:51 PM
  4. CMD Button shows a 2nd dotted focus box
    By mapline in forum Forms
    Replies: 1
    Last Post: 12-02-2010, 05:19 PM
  5. Maintaining Control Focus
    By sabbo64 in forum Programming
    Replies: 3
    Last Post: 08-18-2009, 11:56 AM

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