Class module Question

O

Office_Novice

Greetings,
I would like to build a class module to check that all the values in a
userform are completed. Any direction would be helpful.
 
C

Chip Pearson

You don't need a class module to do this. The validation code can
reside in the UserForm's code module. There is no intrinsic way to
determine whether all the controls have been filled out. You need to
test each control individually and if one is not filled out, display a
message to the user. E.g.,

Private Sub btnOK_Click()
Dim B As Boolean
B = IsFormComplete()
If B = False Then
Msgbox "Form is not complete"
Exit Sub
End If
' form is complete -- do something
End Sub

Private Function IsFormComplete() As Boolean
' Test each control
' if incomplete, then
IsFormComplete= False
Exit Function
' form is complete
IsFormComplete = True
End Function

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
O

Office_Novice

Thanks for the tip. Could you not gather the controls in a collection then
test if the form is complete?
 
C

Chip Pearson

Thanks for the tip. Could you not gather the controls in a collection then
test if the form is complete?


You could, but I don't see what advantage that would bring about. In
general, the best approach would depend on the type of control (e.g.,
TextBox, ComboBox, etc) and what is meant by "complete".

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
O

Office_Novice

Thanks again and hoping not to take to much of your time,
using you function and testing each control with a If statement b is always
false.
where did i go wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top