Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validation Rule on Form

Posted on 2011-02-19
7
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

670 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