Remove focus from subform

richardn

Registered User.
Local time
Today, 05:55
Joined
Nov 6, 2001
Messages
49
I have a form, some buttons on form's footer and a subform.
When I am on subform , and the focus is on a control in the subform, to hide this control I have to remove the focus.
When I tried to move the focus to some controls on the form (parent) , I get an error when hiding last focused control (on subform) because this is still focused.
Of course , first I remove the focus and after that hiding.
If I am moving the focus to another control in the subform, it works well, but it doesn't work when trying to set focus on the parent form .
Somebody can explain whats the reason ?
Thanks
 
I think I understand. You want to move focus off of the subform so that you can hide the entire thing? Use the Expression Builder to locate a control on the main form (it will look something like Forms!FormName!ControlName) and put .SetFocus after it.
 
I found this post yesterday and it describes my problem almost exactly.

I have a main form that displays details about an assembled item. I also have a sub form, displayiing the separate components making up the finished item, with a text box and button next to each. Ths user enters a value into the text box and clicks on the corresponding button to save the entry. There is a button on the main form to save the information displayed on the main form.

After saving the main data, I want to clear the main and sub forms and make the sub form fields invisible.

I find that this process works only as long as I don't make any alterations on the sub form. Otherwise, I get the focus error described in the original issue.

Following the advice given, I set the focus to shift to a field on the main form after each time one of the sub form buttons is clicked. I can see that the focus is being changed, as the main field becomes highlighted. However, when I try to save the main data and clear both forms, I still get a message saying that I can't make the subform field invisible, as it still has focus.

Can two fields have focus at once? If not, why does the application still think that the subform field has focus?
 
I found this post yesterday and it describes my problem almost exactly.
I have a main form that displays details about an assembled item. I also have a sub form, displayiing the separate components making up the finished item, with a text box and button next to each. Ths user enters a value into the text box and clicks on the corresponding button to save the entry. There is a button on the main form to save the information displayed on the main form.

After saving the main data, I want to clear the main and sub forms and make the sub form fields invisible.

I find that this process works only as long as I don't make any alterations on the sub form. Otherwise, I get the focus error described in the original issue.

Following the advice given, I set the focus to shift to a field on the main form after each time one of the sub form buttons is clicked. I can see that the focus is being changed, as the main field becomes highlighted. However, when I try to save the main data and clear both forms, I still get a message saying that I can't make the subform field invisible, as it still has focus.

Can two fields have focus at once? If not, why does the application still think that the subform field has focus?

Each form has a focus item on it. When you change forms, you type on that form's control with focus. So on a subform, something must always have focus. This is also causing me fits. I'm working on a solution that isn't exceptionally hokey. My current theory (untested, follow-up coming soon) is to make a second subform, rather that sfSubformName, sfSubformNameDisabled. That subform has all the same properties, you simply disable everything on it. I am hoping the subform source isn't read-only at runtime :confused:. I'll get back to you guys. Anyone else has any thoughts, they'd be very welcome.
 
Microsoft Visual Basic Help said:
You can use the SourceObject property to identify the form or report that is the source of the subform or subreport on a form or report. You can also use this property for linked unbound object frames to determine the complete path and file name of the file that contains the data linked to the object frame. Read/write String.

It works great to set that property. It's a read/write string property, so you use something like:

Code:
'Enable or Disable controls related to 'Resolved' checkbox
Private Sub EnableDisableControls()
    Dim blShow As Boolean
    'We're counting on the checkbox not being null, which it should never be -- better safe than sorry.
    If Not IsNull(chkResolved) Then
        blShow = Not chkResolved
        cboMaintType.Enabled = blShow
        txtTitle.Enabled = blShow
        cboWorkstation.Enabled = blShow
        cboTechnician.Enabled = blShow
        sfMaintNotes.Enabled = blShow
        sfMaintToDo.Enabled = blShow
        
        'Show the appropriate subform
        sfMaintNotes.SourceObject = IIf((blShow), "sfMaintNotes", "sfMaintNotesDisabled")
        sfMaintNotes.SourceObject = IIf((blShow), "sfMaintToDo", "sfMaintToDoDisabled")
    End If
End Sub

If you make any changes to your main subform, just save it, ctrl+a to highlight all controls, change them to 'Enabled: No' in the properties tool window, and Save As to the disabled form's name.

Money in the bank. :cool:
 
Last edited:
One other quick note: For a professional look, I removed the borders and labels on my subforms and put them on tabs, and leave them 'enabled' all the time. This way, the controls on them are disabled, but you can scroll through the Continuous Forms and see all the data. You also have more room for your continuous subforms, and don't have to worry about the labels for them looking hokey for not being disabled like you would if they were simply parented by the main form.
 
It works great to set that property. It's a read/write string property, so you use something like:

Code:
'Enable or Disable controls related to 'Resolved' checkbox
Private Sub EnableDisableControls()
    Dim blShow As Boolean
    'We're counting on the checkbox not being null, which it should never be -- better safe than sorry.
    If Not IsNull(chkResolved) Then
        blShow = Not chkResolved
        cboMaintType.Enabled = blShow
        txtTitle.Enabled = blShow
        cboWorkstation.Enabled = blShow
        cboTechnician.Enabled = blShow
        sfMaintNotes.Enabled = blShow
        sfMaintToDo.Enabled = blShow
        
        'Show the appropriate subform
        sfMaintNotes.SourceObject = IIf((blShow), "sfMaintNotes", "sfMaintNotesDisabled")
        sfMaintNotes.SourceObject = IIf((blShow), "sfMaintToDo", "sfMaintToDoDisabled")
    End If
End Sub

If you make any changes to your main subform, just save it, ctrl+a to highlight all controls, change them to 'Enabled: No' in the properties tool window, and Save As to the disabled form's name.

Money in the bank. :cool:

yeah, so no one in their right mind would do what you proposed just to resolve a focus / visible issue for a child form.
For 2010 and later, the following works fine:

Private Sub Child1_Exit(Cancel As Integer) 'procedure

form("Name of ParentForm").controlname.SetFocus 'control on Parent Form
form("Name of ParentForm").ChildFormName.visible = False

- or -

Me.controlname.setfocus 'control on Parent Form
Me.childformname.visible = False

End Sub
 

Attachments

  • Capture-example.JPG
    Capture-example.JPG
    24 KB · Views: 252

Users who are viewing this thread

Back
Top Bottom