Re: Query for Subform - G/L Account Transactions (Access XP)
- From: MGFoster <me@xxxxxxxxxxx>
- Date: Sat, 06 Sep 2008 02:12:38 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Your set up is called attribute splitting: putting attributes of one
record into more than one table. You only need one table for the G/L:
CREATE TABLE GeneralLedger (
GLID COUNTER NOT NULL , -- a Counter is an AutoNumber
xact_date DATETIME NOT NULL, -- transaction date
gl_desc TEXT (25) NOT NULL,
gl_ref TEXT (10) NOT NULL,
xact_type TEXT (1) NOT NULL , -- it holds "C," credit or "D," debit.
xact_amt DOUBLE NOT NULL, -- transaction amount
CONSTRAINT PK_GL PRIMARY KEY (xact_date, gl_desc, gl_ref, xact_type)
)
[The above is a data definition language (DDL) command that will create
the table if you run it from a query object (place it in the SQL view.
Get rid of the comments and their leading "--" characters, first.)]
The gl_desc and the gl_ref probably should be Foreign Keys to tables
that hold acceptable descriptions and references numbers.
This system uses positive numbers for both Debit and Credit
transactions.
The Primary Key is iffey 'cuz you may have more than one transaction on
the same date that has the same description, reference, and transaction
type! The GLID is not a good primary key 'cuz it won't prevent
duplicate entries (the main reason for primary keys).
Now you have a pretty easy query to get the data you want:
SELECT GLID, gl_desc, gl_ref,
IIf(xact_type = "C", xact_amt) As DebitAmount,
IIf(xact_type = "D", xact_amt) As CreditAmount
FROM GeneralLedger
This won't really work as a RecordSource for a sub-form, 'cuz of the
IIf() functions. For the Sub-form I'd recommend just having the table
as a RecordSource. Then put the fields: GLID, gl_desc, gl_ref,
xact_type, xact_amt on the form.
Allow the user to select the description, reference, and transaction
type from ComboBoxes. This is where having a separate table of
descriptions and references comes in handy - you'd use them as the
ComboBox's RowSource. The xact_type would just be a ComboBox with a
RowSourceType of Value List and a RowSource of "C", "D".
Remember to set up the xact_amt field so it only accepts positive
numbers.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBSMJJdoechKqOuFEgEQJVsACfYBC5L4Y9r/eSEnfxRQuswccRVzYAoOLj
oDC+JaVEUHMHx8hjI87dKp/N
=+Kau
-----END PGP SIGNATURE-----
Chris O''Neill wrote:
I have a form called frmAccounts that shows information about each financial account in my chart of accounts. This form has several tabs (details, accounting rules, notes, etc) that are all tied together by the account number (tblAccounts.AccountID).
I want to add a tab that shows all G/L transactions for the account, again, linked to the other tabs using the account number. Here's the table structure of my G/L
tblGLHeader:
---------------
GLID Unique ID (autonumber)
Date Transaction date (date)
Desc Transaction description (text)
Ref Transaction source journal reference (text)
tblGLDebits:
--------------
GLDRID Unique ID (autonumber)
SysID Same as GLID (long integer)
DRAcct Debit account (text)
DRAmt Debit amount (currency)
tblGLCredits:
---------------
GLCRID Unique ID (autonumber)
SysID Same as GLID (long integer)
CRAcct Credit account (text)
CRAmt Credit amount (currency)
I want to create a subform that will be placed on the tab that shows the transactions. The subform will be a datasheet with these fields:
GLID (from tblGLHeader)
Description (from tblGLHeader)
Reference (from tblGLHeader)
DebitAmount (from tblGLDebits)
CreditAmount (from tblGLCredits)
A sample line from account 1100 (Bank) might look like this:
GLID Description Reference DebitAmount CreditAmount
-----------------------------------------------------------------------------------------
10 Rent EXPN20 $0.00 $200.00
15 Deposit . INCM30 $100.00 $0.00
Can anyone help me with the SQL query to use to create this subform? Any help would be greatly appreciated as SQL is not one of my strong points.
Regards, Chris
.
- Follow-Ups:
- Re: Query for Subform - G/L Account Transactions (Access XP)
- From: Chris O''Neill
- Re: Query for Subform - G/L Account Transactions (Access XP)
- References:
- Query for Subform - G/L Account Transactions (Access XP)
- From: Chris O''Neill
- Query for Subform - G/L Account Transactions (Access XP)
- Prev by Date: Query for Subform - G/L Account Transactions (Access XP)
- Next by Date: Nz function
- Previous by thread: Query for Subform - G/L Account Transactions (Access XP)
- Next by thread: Re: Query for Subform - G/L Account Transactions (Access XP)
- Index(es):
Relevant Pages
|