Solved

Validation Rule on Form

Posted on 2011-02-19
7
379 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
Backup Your Microsoft Windows Server®

Backup 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 119

Expert Comment

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

Accepted Solution

by:
Rey Obrero 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained 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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now