473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding a validation rule to a form to stop duplicate records

dragonsbreath
4 New Member
Firstly I am not a coder.

I am trying to add a validation rule to an input form that will prevent users’ creating more than one record per organisation.

This DLookUp seems to work

=DLookUp("[org]","[Org_Sen]","[org]=" & [Form].[org]) Is Null

If the user tries to select a organisation that already has a record the validation text is displayed so far so good - but when the user deletes the entry and tries to close the form I get a syntax error “(missing operator) in the query expression”

any ideas what I am doing wrong
May 15 '07 #1
6 11045
puppydogbuddy
1,923 Recognized Expert Top Contributor
Eliminate the equal sign preceding your expression. If that doesn't work, try changing your expression to the following:

Expand|Select|Wrap|Line Numbers
  1. nz(DLookUp("[org]","[Org_Sen]","[org]=" & [Form].[org]) ,0) = 0
May 15 '07 #2
dragonsbreath
4 New Member
Thanks for the advice but it is still not working.

I think I need to clarify -

I am trying to add a validation rule to a dropdown input box on a form that will bring up an error message if the user tries to select an organisation that already has a record.

I have tried putting the above validation code in the property box of the field on the form and it works to some extent, it will not allow a user to add a record for an organisation that already exists, and a pop up message does appear. If the user selects another organisation that does not have a record then no problem, however if the user tries to delete the selection and close the form I get a syntax error.

I want the user to be able to delete the selection and exit the form - any ideas?
May 16 '07 #3
Denburt
1,356 Recognized Expert Top Contributor
Since you have validation rules in place there is never a need to delete any record since a record can not be created if it violates the rule. Try using Undo to release any fields that are bound with data that should resolve the issue.
May 16 '07 #4
dragonsbreath
4 New Member
I think I have the syntax wrong in the rule, as from the dropdown you select a duplicate organisation the error message pops up and if you try and do anything with the duplicate organisation in field I get the error message. If I delete the selection and click on undo or exit I get a syntax error.
May 16 '07 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
Ok, when a previous selection from the combobox is deleted (blanked out), the combobox control is empty ("") rather than null, and therefore is not covered by your validation rule. There are several ways you can handle this. I would try putting the following code in the AfterUpdate event of your combobox.
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourCombobox_AfterUpdate()
  2. If Me!YourCombobox.Value = "" Then
  3. MsgBox "Please make a selection or Exit."
  4. Exit Sub
  5. End If
  6. End Sub
May 16 '07 #6
dragonsbreath
4 New Member
Thanks that worked.

I had to simplify my validation rule to:

=DLookUp("[org]","[Org_Sen]") Is Null

that with the above code solved my problem.
May 17 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andrew | last post by:
I've ripped off some script from another site of mine that works fine which checks an input box to see if an email address has been entered when submitting. If it hasn't a prompt is issued asking...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
6
by: Chuck | last post by:
A97. A database has a table: tblA which has a single text field, B. It is a primary field, indexed and no duplicates. It is used as a lookup for table tblC. A form based on tblA is used to add...
3
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an...
1
by: RyanL | last post by:
All, I have an append query set up that pulls records off of one table and appends them to a linked table. However, when the query runs, it gives me an error message saying that the records could...
1
by: Catriona | last post by:
I am developing an Access application where users insert bill records for an electricity account by clicking on a new button. The required workflow is 1) New button clicked 2) New record appears...
9
by: Dhiru1009 | last post by:
Hi guys, I am trying to build a user registration form using PHP and MYSQL but encountring a problem. When I click on submit with empty fields it adds records to database also it doesn't matter...
8
by: Bryan | last post by:
I want my business objects to be able to do this: class Person(base): def __init__(self): self.name = None @base.validator def validate_name(self): if not self.name: return
18
by: ChipR | last post by:
I have a text box with a validation rule and validation text. When entering a new record, if I put in invalid text, the validation text is displayed in a message box, but after clicking OK, another...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.