error message if multiple index is violated

sprite66

New Member
Joined
Aug 4, 2006
Messages
9
Hi,

I'm creating a contact information database. I have created a multiple field index for first and last name and I would like an error message to appear as soon as these two fields are filled if the contact is already in the database. Is there any way to create a validation rule for two fields?

Any suggestions about how to get an error message to display "Contact already in database" would be greatly appreciated.

Thanks in advance :)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

VicRauch

Well-known Member
Joined
Mar 23, 2006
Messages
2,032
In the AfterUpdate event of both fields have code that will call a CheckForDup() function. By putting it into both fields, any changes will always be checked.

The CheckForDup() function would then do a DLookup to see if the name is already present.
Code:
ReturnValue = DLookup("RecordID", "tblContactInformation", "FirstName='" & Me.FirstName & "' AND LastName= '" & Me.LastName)
This line of code will put the RecordID into the ReturnValue variable if there is a record that matches.

HTH,
 

giacomo

Well-known Member
Joined
Feb 20, 2002
Messages
1,796
Not sure what you're using this database for but one thing to consider is that it's not that uncommon to have different contacts with the same name.
 

sprite66

New Member
Joined
Aug 4, 2006
Messages
9
Thank you both for your help...I have it figured out now.

Giacomo, thanks for the resource links :biggrin:
 

Forum statistics

Threads
1,136,702
Messages
5,677,290
Members
419,684
Latest member
BOB101

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top