Solved

Validation Rule on Form

Posted on 2011-02-19
7
378 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Database connect change in Access 2015 5 34
Conditional Formatting - Date() 8 25
How calculate median 5 38
Query 14 0
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 Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

760 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

25 Experts available now in Live!

Get 1:1 Help Now