Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-27
3
Medium Priority
?
1,249 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
[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
3 Comments
 
LVL 39

Assisted Solution

by:PatHartman
PatHartman earned 1000 total points
ID: 39959083
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
ID: 39959137
don't think I made myself clear so have attached a doc showing the info.  Thanks
Serial-Validation.doc
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 total points
ID: 39959207
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

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

609 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