Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Validation Rule on Form

Posted on 2011-02-19
7
Medium Priority
?
389 Views
Last Modified: 2012-08-13
See attached form frmPrices.

I want to force the user to choose a value from the combo for Product Code.

How do I force this and prevent them from leaving the field without choosing from the dropdown.
I put Len([productCode] & "")>0  in the form validation but this has no effect.

(I have experimented with this validation in the past and never can get it to work ... I must be missing something!)
Database1.mdb
0
Comment
Question by:Patrick O'Dea
  • 4
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34934954
place this in the beforeupdate event of the form

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Product & "" = "" Then
    MsgBox "Select Product Code"
    Cancel = True
    Me.Product.SetFocus

End If
End Sub
0
 

Author Comment

by:Patrick O'Dea
ID: 34934971
Thanks capricorn1,

I understand that.

Can you comment at all on why the validation in the form does not work ??
Why do I need to use VBA to do such a simple validation?
Any thoughts on the above appreciated.

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34934994
if you don't validation done in the form, set the Required property of the field to Yes (in design view of table)


<Can you comment at all on why the validation in the form does not work ?? >
what do you mean by, it does not work? explain
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Patrick O'Dea
ID: 34935027
"if you don't validation done in the form, set the Required property of the field to Yes (in design view of table)"

Yes, point taken, but that validation is not activated until I try to save the record.  I wanted immediate validation upon leaving the field.


<Can you comment at all on why the validation in the form does not work ?? >
what do you mean by, it does not work? explain .

I put a validation rule on the ProductCOde field in the form "Len([productCode]&"")>0".
Why does this not stop me from exiting the field after making no entry??

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34935032
< I wanted immediate validation upon leaving the field.>
use the exit event of the control
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 34935065
private sub product_exit(cancel as integer)

if me.product & "" = "" Then
    MsgBox "Select Product Code"
    Cancel = True
End If

end sub
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 34935078
Thanks again!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question