473,503 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation between fields in different tables in Access

9 New Member
Hi everyone - here is my problem:

I've got an Access 2002 database with a table [demographics] and a field (not the primary key) called [dateofbirth]. This table has a one to many relationship with a table called [lines]. [Lines] includes a field called [insertiondate].

I've built a subform based on [lines] with parent form [demographics]. I want to validate [insertiondate] against [dateofbirth] ensuring that [insertiondate] is not before [dateofbirth].

Is this possible - can I validate one field against another in a different table?

Thanks - Michael
May 25 '07 #1
4 4021
kiwipedia
9 New Member
Well I've got my DOB data onto the subform using DLookup to extract the appropriate DOB from the demographics table.
The code runs whenever the insertion date gets focus.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Insertion_GotFocus()
  2. Dim datDOB As Date
  3. datDOB = DLookup("DOB", "demographics", "[NHI] = Form![NHI]")
  4. If (Not IsNull(datDOB)) Then Me.DateofBirth = datDOB
  5. End Sub 
Should be easy enough to now validate the Insertion date against the DOB - I'll hopefully finish it off tomorrow.

Michael.
May 25 '07 #2
NeoPa
32,557 Recognized Expert Moderator MVP
If your [DateofBirth] control is on the main form and you have [Insertion] on the sub-form then try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Insertion_BeforeUpdate(Cancel As Integer)
  2.   If Me.Insertion <= Me.Parent.DateofBirth Then
  3.     'MsgBox() is optional
  4.     Call MsgBox("Error Message", , "Title")
  5.     Cancel = True
  6.   End If
  7. End Sub
May 26 '07 #3
kiwipedia
9 New Member
If your [DateofBirth] control is on the main form and you have [Insertion] on the sub-form then try :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Insertion_BeforeUpdate(Cancel As Integer)
  2.   If Me.Insertion <= Me.Parent.DateofBirth Then
  3.     'MsgBox() is optional
  4.     Call MsgBox("Error Message", , "Title")
  5.     Cancel = True
  6.   End If
  7. End Sub

Thanks NeoPa - a much more efficient solution and works nicely.

Michael.
May 27 '07 #4
NeoPa
32,557 Recognized Expert Moderator MVP
Thanks NeoPa - a much more efficient solution and works nicely.

Michael.
Not a problem Michael.
I'm glad it worked for you :)
May 29 '07 #5

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

Similar topics

21
3881
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
0
863
by: jake | last post by:
I have an XML file that needs to fill 4 MS Access tables and then later after processing I need to export back to the same structured but different XML file. I also have to validate the XML file...
0
2322
by: Steve V | last post by:
I'm using Access 2000 to build a budgeting/tracking database. Can I make a validation rule (using VBA) that checks the data as if the record has already been added? I've got 5 tables (only the...
5
10853
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
3
6314
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...
12
2031
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
11
2958
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
7
3580
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
5955
by: Harlequin | last post by:
I must start this posing by making the point that I am NOT a VB programmer and I'm something of a Newbie to MS Access. I can program in a number of languages (Java, Javascript, PERL,PHP and TCL) but...
7
5943
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer...
0
7192
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
7064
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
7261
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
7445
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
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4991
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
3158
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
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
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.