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,193 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 38

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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