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,153 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 35

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

832 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