PDA

View Full Version : Validating Sheet



c19h28O2
02-08-2006, 06:08 AM
Hi,

I was wondering how to validate a sheet before it can be saved, i have a few texts boxes and fields that need filling out, however i would like to force the user to fill out all of the fields before it can be saved...

I have a little knowledge of VBA if i would need to go that route.

Thanks

C19

Rembo
02-08-2006, 06:51 AM
I was wondering how to validate a sheet before it can be saved, i have a few texts boxes and fields that need filling out, however i would like to force the user to fill out all of the fields before it can be saved...


Hi,

Here's a simple way to handle it. If you have to click CommandButton1 to exit the form, add this code to the UserForm code page:

Private Sub CommandButton1_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If Left(ctl.Name, 7) = "TextBox" Or Left(ctl.Name, 8) = "ComboBox" Then
If ctl.Value = "" Then
MsgBox ("You didn't fill out the form completely." & Chr(13) & _
"Please fill in the blanks")
Exit Function
End If
End If
Next ctl

'Do the rest of your stuff here

End Sub

Hope that helps,

Rembo

austenr
02-08-2006, 01:56 PM
Cross post on Mr Excel board