ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Validating Data in User Forms (https://www.excelbanter.com/excel-programming/410305-validating-data-user-forms.html)

JPA

Validating Data in User Forms
 

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.

JPA

Validating Data in User Forms
 
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).


"JPA" wrote:


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.


NateBuckley

Validating Data in User Forms
 
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


"JPA" wrote:

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


"JPA" wrote:


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.



All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com