Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subform Control Focus

Status
Not open for further replies.

chew1920

Programmer
Jan 11, 2005
25
US
I have a form with multiple subforms, and on each subform there are command buttons that I enable/disable from the parent form. When I have clicked one of the subform controls, I have the focus shifted back to the parent form which works fine, but when I try to disable the subform controls from a control on the parent screen, I get an error saying it can't disable a control that has focus and it breaks on the subform control that was just used. How can I get this to work for a subform that has data, and for a subform that has no data?
 
G'day... if you click a button on the main form, to disable buttons in subforms, that button MUST have the focus. In which case, you won't get the error.

So... must be a prob with your code. If you want to check which control has the focus at anytime, try adding this to the beginning of the code that disables the subform buttons:

Code:
    msgbox "The contol with Focus is: " & screen.activeControl.name

At least this way you'll know for sure what has focus!

If you're still having issues, post the relevant code and I'll bet someone here will spot the prob.

HTH

Max Hugen
Australia
 
When I open the form, I click the disable code that is listed below (this works fine), after that I click cmdEdit on sfrmName which opens a new window. I immediately close the new window, and before I click anything else on the subform, I click the disable button again and I get an error that says "You can not disable the control that has focus" The code breaks when it tries to set the button that was pressed. When I added the message box, I told me the active control was the one on the parent screen. Any other ideas would be appreciated. The only thing I thought of is to create a sub that will check the disabled status before any of the buttons is pressed and provide a message if they are not enabled.

Code:
    Me.txtDictionaryID.SetFocus
    Me.cmdAddNew.Enabled = Not bLock
    Me.cmdVerify.Enabled = Not bLock
    Me.cmdObsolete.Enabled = Not bLock
    Me.sfrmCAS.Form.cmdEdit.Enabled = Not bLock
    Me.sfrmCAS.Form.cmdDelete.Enabled = Not bLock
    Me.sfrmCAS.Form.cmdAddNew.Enabled = Not bLock
'*** Error Right Here
    Me.sfrmName.Form.cmdEdit.Enabled = Not bLock
    Me.sfrmName.Form.cmdDelete.Enabled = Not bLock
    Me.sfrmName.Form.cmdAddNew.Enabled = Not bLock
    Me.sfrmDesignation.Form.cmdEdit.Enabled = Not bLock
    Me.sfrmDesignation.Form.cmdDelete.Enabled = Not bLock
    Me.sfrmDesignation.Form.cmdAddNew.Enabled = Not bLock
    Me.sfrmComment.Form.cmdEdit.Enabled = Not bLock
    Me.sfrmComment.Form.cmdDelete.Enabled = Not bLock
    Me.sfrmComment.Form.cmdAddNew.Enabled = Not bLock
 
chew1920, when you say you:
I click the disable code
what do you click on, and is it in the main form?

Also, try inserting the msgbox code I provided above, at the spot where it fails, so that you know for sure what has focus.

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top