Close subform hide subform

natep26

Registered User.
Local time
Today, 11:49
Joined
Oct 2, 2007
Messages
63
I have a main form with tabs. On the third tab I have two subforms which are invisible. There are two checkboxes on the mainform. Each checkbox makes one of the two forms visible. When a form becomes visible, data can be added to the form and is put into a table upon clicking the Save button. I would like the Save button click to also make the form invisible once again.

This is the code I have on the main form:

Private Sub epsinspcheck_AfterUpdate()
'After Update of checkbox Check if Active checkbox is selected then show or hide subform
If Me.EPSInspCheck = True Then
Me.sfinspeps.Visible = True
Else
Me.sfinspeps.Visible = False
End If

'disables conditions/repaircheck if epscheck is selected
If Me.EPSInspCheck = True Then
Me.conditionrepaircheck.Enabled = False
Else
Me.conditionrepaircheck.Enabled = True
End If

End Sub
Private Sub conditionrepaircheck_afterupdate()
'After Update of checkbox Check if Active checkbox is selected then show or hide subform
If Me.conditionrepaircheck = True Then
Me.sfEPSConditionsRepairs.Visible = True
Else
Me.sfEPSConditionsRepairs.Visible = False
End If

'disables epscheck if conditions/repairs check is selected
If Me.conditionrepaircheck = True Then
Me.EPSInspCheck.Enabled = False
Else
Me.EPSInspCheck.Enabled = True
End If

End Sub

Private Sub Form_Current()
'On current event of main form Check if Active checkbox is selected then show or hide subform
If Me.EPSInspCheck = True Then
Me.sfinspeps.Visible = True
Else
Me.sfinspeps.Visible = False
End If

If Me.conditionrepaircheck = True Then
Me.sfEPSConditionsRepairs.Visible = True
Else
Me.sfEPSConditionsRepairs.Visible = False
End If
End Sub

This is the code I have on the subform

Private Sub bSave_Click()
On Error GoTo Err_BSAVE_Click

'Saves current record and closes form
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Forms!sfinspeps.Visible = False

Exit_BSAVE_Click:
Exit Sub

Err_BSAVE_Click:
MsgBox Err.Description
Resume Exit_BSAVE_Click

End Sub
Private Sub bCancel_Click()
On Error GoTo Err_bCancel_Click

'Looks for changes/edits and undoes them
If Me.Dirty Then
Me.Undo
End If

'Closes form
Forms![sfinspeps].Visible = False

Exit_bCancel_Click:
Exit Sub

Err_bCancel_Click:
MsgBox Err.Description
Resume Exit_bCancel_Click
End Sub

I get the error that Access can't find the form sfinspeps referred to in the code. I have also tried variations.

Help would be apprecited.

Thanks
 
Yep. I'm using the container name.
 
If this button is on the main form then try it this way:

Me.sfinspeps.Visible = False

If the button is on the subform then:

Set focus to a control on the main form and use
Me.Visible = False
 
The button is on the subform. How do I set focus to a control on the main form?
 
Pick a control which seems like it would be a natural on the main form to go back to. Then, just use

Me.Parent.YourControlName.SetFocus
Me.Visible= False
 
Thanks Bob. That did it for me. I appreciate your help.
 

Users who are viewing this thread

Back
Top Bottom