473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation rule across tables using form's BeforeUpdate event

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 necessary fields are shown here):
tblBudgetCatego ries
catName:Text
catTaxTrack:Yes/No

tblBudgetPeriod s
bpdName:Text
bpdBegin:Date
bpdEnd:Date

tblBudget
bgtPeriod:Text (from tblBudgetPeriod s.bpdName)
bgtCategory:Tex t (from tblBudgetCatego ries.catName)
bgtAmount:Curre ncy

tblTransactions
trnID:Autonumbe r
trnDate:Date
trnType:Text (e.g. cash, charge, check, etc.)
trnReceipt:Yes/No

tblCharges
cgsTransID:Long Integer (from tblTransactions .trnID)
cgsCategory:Tex t (from tblBudgetCatego ries.catName)
cgsAmount:Curre ncy

I've got frmBudgets and sfmBudgetAmount s based on tblBudgetPeriod s and
tblBudget, respecively; frmCashFlow and sfmCashFlowAmou nts based on
tblTransactions and tblCharges, respectively; and frmCategories based on
tblBudgetCatego ries.

I'm having trouble implementing 2 validation rules:
1. Each transaction and charge must correspond to a defined budget period
and budget category amount.
2. If any charge for a transaction corresponds to a category with
catTaxTrack=Yes , then the trnReceipt must be Yes.

I think the solution to one of them will enable me to implement the other in
a similar manner.

Here's what I've done for Validation Rule 1 in frmBudgets:
Private Sub Form_BeforeUpda te(Cancel As Integer)
Dim strSql As String

' Check that all transactions belong to a budget
strSql = "SELECT [qryTransactions &Charges].[trnDate], " & _
"[qryTransactions &Charges].[cgsCategory], " & _
"[qryPeriods&Budg ets].[bpdName], " &_
"[qryPeriods&Budg ets].[bgtCategory] " & _
"FROM [qryTransactions &Charges] " & _
"LEFT JOIN [qryPeriods&Budg ets] " & _
"ON ([qryTransactions &Charges].[trnDate]<= " & _
"[qryPeriods&Budg ets].[bpdEnd]) " & _
"AND ([qryTransactions &Charges].[trnDate]>= " & _
"[qryPeriods&Budg ets].[bpdBegin]) " & _
"AND ([qryTransactions &Charges].[cgsCategory]=" & _
"[qryPeriods&Budg ets].[bgtCategory]) " & _
"WHERE ([qryPeriods&Budg ets].[bpdName] Is Null);"
Set rstCheck = CurrentDb.OpenR ecordset(strSql )
If rstCheck.Record Count > 0 Then
MsgBox ("Cannot save budget period information because it would " & _
"leave cash flow without a corresponding budget")
Cancel = True
End If
End Sub

qryTransactions &Charges is an inner join between tblTransactions and
tblCharges at the database level.
qryPeriods&Budg ets is an inner join between tblBudgetPeriod s and tblBudget at
the database level.
These inner joins must be done separately to avoid "ambiguous outer joins".

The potential beauty with the preceeding sub is that it could be employed
without changes (except for the message) in frmBudgets, sfmBudgetAmount s,
frmCashFlow, and sfmCashFlowAmou nts. The problem with the preceeding sub is
that the SQL query does not consider the record that was just entered, i.e.
the one that is important.

Is there an easy way to get Access to consider the new record? Maybe by
cloning the table, adding the record to the dummy table, and testing there
(if so, how do I do it--I don't have any experience with cloning)? Can I add
the record, test, and delete (if necessary)? Or am I going about this the
wrong way?

Any suggestions, solutions, or examples are appreciated.

Steve
Nov 12 '05 #1
0 2327

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15906
by: Dalan | last post by:
I apparently need a bit of assistance regarding the structure of some validation code on the BeforeUpdate or AfterUpdate event on a form for several fields that need to controlled. I did search the archives, but found nothing precise enough to address my specific needs. 1. There are three text box fields on the form and one of the three...
2
4270
by: Dalan | last post by:
This ought to be simple enough, but not certain which to use. I have a few fields set to Require data to be entered; however, the message displayed by Access 97 is too generic to be of any real value. I tried attaching a specific message for this in the table properties, but was unsuccessful. Can this be done? I then opted for Not Is Null...
2
2826
by: R Bolling | last post by:
I am using a routine to check to see if a phone number (PK) has alread been entered, and takes the user to that record if it is found -- as follows: Private Sub Contact_telephone___BeforeUpdate(Cancel As Integer) Dim rs As DAO.Recordset Dim iAns As Integer Set rs = Me.RecordsetClone rs.FindFirst " = '" & Me! & "'" If Not rs.NoMatch Then
5
518
by: Sandy | last post by:
Entries will look like: 01-02 02-03 03-04 and will include a space at the end. I need help on creating a validation rule for these entries. Thank You!
6
3682
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 new records. The Validation Rule: <>!! was made using the expression builder. The rule produces this error: The expression you entered in the...
2
2122
by: Ben.j.howard | last post by:
In my table i would like to create a validation rule for a yes/no field. I would like it, to only allow you to check yes, if two other fields are already ticked as yes. Example; Field 1: Order confirmed (yes/no) Field 2: Order ready to ship (yes/no) Field 3: Shipped (yes/no)
3
2018
by: BrianB830 | last post by:
Hello all, I have a quick question regarding an MS Access database I'm creating. In the entity "ORDER", I have the attributes "Order Date" and "Delivery Date". I need to create a validation rule here. The delivery date must come after the order date. Would anyone be able/willing to help?
6
3118
by: lorirobn | last post by:
Hi, I have a form with a continuous subform. I am working on putting validations in for the subform's required fields. Being somewhat new to Access (or rather, an antiquated mainframe programmer), I finally figured out that the place to put the validations is in Form_BeforeUpdate. I have 2 questions: 1) once I determine there is an...
5
5584
by: michael.meenan | last post by:
I'm trying to limit the number of records that can have a checkbox clicked. I created a query that counts the number of records with that checkbox clicked and tried to make a form validation expression "(Count total of field) <= (maximum number of records permitted to have this checkbox clicked)" and it doesn't work. Help! I also tried...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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 we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.