View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ken McLennan[_6_] Ken McLennan[_6_] is offline
external usenet poster
 
Posts: 5
Default Userform Control validity check

G'day there Gary,

Sorry I wasn't more clear. Normally, I would not allow the "Enter Data"
button to be enabled until all fields were validated as 'good-to-go'.
This precludes, then, that each control would validate user
inputs/selections in an event procedure (Change/Click or ?) and
increment a variable that totals the correct number of required
inputs/selections. Once this is reached the "Enter Data" button gets
enabled.


That makes sense.

I don't see anything here that would clear the listboxes.


Neither did I but that didn't stop it from happening, unfortunately.
Even the severe blast of swear words I unleashed at it didn't help :(

I would color the background of all controls that require
inputs/selections with a non-offensive color like light green or light
yellow. This provides a visible cue that these fields are mandatory.


Fine idea, so I did that.

I would validate the inputs in the textboxes/combobox in the
AfterUpdate event. Here I'd set the backcolor to white if inputs are
valid.


Text & Combo boxes worked fine with this method. Thanks for that.

ListBoxes:
The way you test the multi-select listboxes is fine but why keep going
once you find a selected item? Using the listbox's Change event tells
you that a selection has happened, but not if an item was unselected,
and this will fire for each selection change. Instead, I'd use the
AfterUpdate event to run your loop, adding to the counter and exiting
the loop when the 1st selected item is found.

Private Sub ListBox9_AfterUpdate()
With Me.ListBox9
For int_X = 0 to .Listcount - 1
If .Selected(int_X) Then _
lValidInputs = lValidInputs + 1: .BackColor = vbWhite: Exit For
Next 'int_X
End With 'Me.ListBox9
Me.cmdEnterData.Enabled = (lValidInputs = lREQD_FIELDS)
End Sub 'ListBox9_AfterUpdate()


Unfortunately, the AfterUpdate event didn't fire. I did get something
happening with the Change event, but that led to another situation where
I could select/deselect items in the first listbox which incremented the
count allowing the Enter Data commandbutton to become active when there
were no entries in the second listbox. I should be able to adjust the
counting mechanism somewhere, but I've not had a chance to work on it
yet. I'm still confused as to why the AfterUpdate event didn't work.

Now, your "Enter Data" button is only available AFTER all
inputs/selections are validated, and it only has to process the data.
The CompleteRecord function is no longer needed. The controls validate
themselves as the user interacts with each one.


Thanks very much for your advice. It makes much more sense to do it the
way you suggested. I think it will be fine if I can figure out the
AfterUpdate bit. I'll have to work on it some more, but probably not today.

Thanks very much for your assistance. If you have any further ideas I
would certainly appreciate them, but if not (or if you actually have a
life) I'm sure you've pointed me in the right direction for which I'm
grateful - and have learned some useful techniques.

Thanks again
Ken McLennan
Qld, Australia