Shubham
Shubham

Reputation: 979

Access VBA: How to control element when it has focus

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

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!

Upvotes: 0

Views: 2002

Answers (1)

mwolfe02
mwolfe02

Reputation: 24207

You must first set the focus to a different control.

That said, if you really have no other control to send the focus to (which I'd find hard to believe), there is a "workaround." You can add a command button and set its TabStop property to False and its Transparent property to True and set the focus to that control.

Upvotes: 1

Related Questions