Solved

How to set up validate rule to check a query that the serial number does not exist

Posted on 2014-03-27
3
1,130 Views
Last Modified: 2014-03-27
Have a table form for data entry and one of the fields is to enter the serial number.  Want to use the validation rule to check a query (need the query cause want it to check only records not annotated as closed for the serial number existence).  Do not want to allow the user to enter a serial number that already exist on a record not annotated as closed (which is a checkbox field in the record of the table).  Am using the query as the closed field is in the order hdr table and the serial number is in the order line table.
0
Comment
Question by:HFSCI
3 Comments
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
Comment Utility
You can't do this with a validation rule.  You will need to do it with code in the BeforeUpdate event of the control on the form.

If Dcount("*", "yourtable", "Closed = False") > 0 Then
    Msgbox "This serial number already exists.  Please enter another.",vbokOnly
    Cancel = True
    Exit Sub
End If

Open in new window


If you want to clear the serial number, add:
Me.txtSerialNum.undo
between Cancel and Exit.

I rarely erase something that the user has typed.  It is usually better for them to see what they typed so they can correct it rather than forcing them to enter the entire value again.  This is particularly relevant with long number strings.

If you have a SQL Server BE  you can create a trigger that will perform this validation.  Since the trigger is applied at the table level, it is a much more robust solution because it will be enforced regardless of where the update request comes from.  Using form events means that your business rule will only be applied if you do the update via that particular form.  A2010+ (and possibly A2007 but I'm not sure) support data macros which are similar to triggers.  I don't know if they have the ability to run queries but you could look into it.
0
 

Author Comment

by:HFSCI
Comment Utility
don't think I made myself clear so have attached a doc showing the info.  Thanks
Serial-Validation.doc
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
use the beforeUpdate event of the textbox for serial

private sub txtserial_beforeUpdate(cancel as integer)

if dcount("*","Open serial","serial='" & me.txtserial &"'")>0 then
   msgbox "Serial already exists!"
end if


end sub
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

8 Experts available now in Live!

Get 1:1 Help Now