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,160 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 36

Assisted Solution

by:PatHartman
PatHartman earned 250 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 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

830 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