View Single Post
Old 11-24-2019, 07:04 PM   #15
Weekleyba
Registered User
Silver Supporter
 
Join Date: Oct 2013
Location: North Dakota
Posts: 188
Thanks: 109
Thanked 7 Times in 7 Posts
Weekleyba is on a distinguished road
Re: Closing a Form after Validation

Thank you DBguy! That works great.
Of course that leads to the next step that I'm trying to figure out and that is checking to see if the all the controls are empty and if so, clicking the Close button allows the form to close.
I could present a separate thread but I think it might be fine here.

Here's what I've tried in the form F_Project, CloseButton On Click event.

#Private Sub Command5CloseButton_Click()
'This is for the close button.
If CheckForEmpty(Me) = False Then
DoCmd.Close
ElseIf ValidationOfControl(Me) = False Then
DoCmd.Close
End If
End Sub#

And the public function CheckForEmpty,

#Public Function CheckForEmpty(frm As Access.Form) As Boolean
Dim ctl As Control
Dim boolEmptyBox As Boolean

For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
If (IsNull(ctl.Value) Or ctl.Value = "") Then
boolEmptyBox = True
End If
End If
Next ctl
CheckForEmpty = boolEmptyBox
End Function#

I can't figure out why it doesn't work.
Any suggestions?
Thanks.
Weekleyba is offline   Reply With Quote