PC Review


Reply
Thread Tools Rate Thread

Class module Question

 
 
Office_Novice
Guest
Posts: n/a
 
      26th Nov 2008
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.
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      26th Nov 2008

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)


On Wed, 26 Nov 2008 06:13:01 -0800, Office_Novice
<(E-Mail Removed)> wrote:

>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.

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      26th Nov 2008
Thanks for the tip. Could you not gather the controls in a collection then
test if the form is complete?

"Chip Pearson" wrote:

>
> 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)
>
>
> On Wed, 26 Nov 2008 06:13:01 -0800, Office_Novice
> <(E-Mail Removed)> wrote:
>
> >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.

>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      26th Nov 2008


>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)

On Wed, 26 Nov 2008 07:21:00 -0800, Office_Novice
<(E-Mail Removed)> wrote:

>Thanks for the tip. Could you not gather the controls in a collection then
>test if the form is complete?
>
>"Chip Pearson" wrote:
>
>>
>> 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)
>>
>>
>> On Wed, 26 Nov 2008 06:13:01 -0800, Office_Novice
>> <(E-Mail Removed)> wrote:
>>
>> >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.

>>

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      26th Nov 2008
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?

"Chip Pearson" wrote:

>
>
> >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)
>
> On Wed, 26 Nov 2008 07:21:00 -0800, Office_Novice
> <(E-Mail Removed)> wrote:
>
> >Thanks for the tip. Could you not gather the controls in a collection then
> >test if the form is complete?
> >
> >"Chip Pearson" wrote:
> >
> >>
> >> 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)
> >>
> >>
> >> On Wed, 26 Nov 2008 06:13:01 -0800, Office_Novice
> >> <(E-Mail Removed)> wrote:
> >>
> >> >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.
> >>

>

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      26th Nov 2008
Nevermind. I figured out what i was doing wrong thanks a lot Chip.

"Office_Novice" wrote:

> 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?
>
> "Chip Pearson" wrote:
>
> >
> >
> > >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)
> >
> > On Wed, 26 Nov 2008 07:21:00 -0800, Office_Novice
> > <(E-Mail Removed)> wrote:
> >
> > >Thanks for the tip. Could you not gather the controls in a collection then
> > >test if the form is complete?
> > >
> > >"Chip Pearson" wrote:
> > >
> > >>
> > >> 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)
> > >>
> > >>
> > >> On Wed, 26 Nov 2008 06:13:01 -0800, Office_Novice
> > >> <(E-Mail Removed)> wrote:
> > >>
> > >> >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.
> > >>

> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Module Question Doug Maddox Microsoft Excel Programming 1 23rd Dec 2010 08:43 AM
Class Module question WhytheQ Microsoft Excel Programming 0 1st Jun 2006 12:07 PM
Class Module Question Andrew Yates Microsoft Excel Programming 8 5th Mar 2006 03:50 PM
Class module question =?Utf-8?B?RGF2aWQ=?= Microsoft Excel Programming 1 8th Sep 2005 04:51 PM
Class Module question. Lee Taylor-Vaughan Microsoft Access Form Coding 4 25th Jul 2003 09:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.