Solved

Validation Rule on Form

Posted on 2011-02-19
7
381 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 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