Error: can't disable a control while it has the focus

Status
Not open for further replies.

merce33

Active Member
Joined
Oct 27, 2006
Messages
277
EDIT*** This post belongs in the ACCESS forum, sorry!

I get runtime error 2164 "can't disable a control while it has the focus" when i run the following code. why?

Code:
    With Forms!frmDefectSheets
        'main form frmDefectSheets was previously disabled, need to enable it now that
        'a scan has been made. turning ON the main form
        .AllowEdits = True
        .fSubDefectLineItems.Enabled = True
        .txtQtyProduced.Enabled = True
        
        'set the focus elsewhere so that me.txtBarcode can be disabled
        .SetFocus
        .txtQtyProduced.SetFocus
        .SetFocus
        .txtDateCollected.SetFocus
        .SetFocus
        .txtQtyProduced.SetFocus

        'deactivate barcode textbox until record is saved
        'turning OFF the barcode textbox so no scans can be made until a save
       'THIS IS WHERE THE ERROR IS OCCURRING, BUT WHY?
        Me.txtBarcode.Enabled = False
        
        'set focus on defect sheet form and filter to the scanned record
        .SetFocus
        DoCmd.ApplyFilter , "idsDefectSheetID = " & Me.txtBarcode.Value
        .Refresh
        .Requery
        
        'assign date collected time if it didn't already have one
        If IsNull(.txtDateCollected) Then .txtDateCollected.Value = Now()
        
    End With

as you can see, i have set the focus on a different control and thus should be able to disable it.
any suggestions? The Barcode textbox under question simply receives a barcode scan. i then want to filter the form based on the scan, enable certain controls, and disable the box that received the scan, such that no other scans can be made until the record is saved.

thanks,
Mike
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Status
Not open for further replies.

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top