Validating Data in User Forms

  • Thread starter Thread starter JPA
  • Start date Start date
J

JPA

I have a fairly simple issue but am not quite sure what the solution is:

Have created a basic form in Excel with several combo boxes.
The combo drop down values are "Y" or "N".

I have a command button that adds the values to a worksheet and clears the
combo boxes.

How do I prevent users from adding blank values to the worksheet? Ideally,
I would like to create an error routine/procedure which informs the user that
no blank values are allowed and highlights (or moves the cursor to) the field
with the blank value.

Thanks.

JPA.
 
Just a clarification from me - the poster of this thread.

I would like the error procedure to run from the form. Blank entries should
not be allowed on the form

The worksheet being written to is hidden and should stay that way (users
should not see it).
 
I hope this helps but what I would do is this

say you have two textboxes you wish to contain data before proceeding

Private Sub CommandButton1_Click()

dim hasError as boolean
hasError = false
if textBox1.Value = "" or textBox2.Value = "" then
hasError = true
end if
if hasError then
msgBox "You must enter zee information!"
else
'Validation has passed, so in here do your thing.
end if

I'm using a boolean (true or false), that is set to true ONLY IF textBox1 or
textBox2 contains a blank value.
If it does then set hasError (which is teh boolean) to true.

Hope this helped a little bit.

Hope that helped slightly.

End Sub
 

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

Back
Top