473,395 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Recordsets & Append query


Hi there

I have 2 tables: tblAccuracy & tblClearance

Users add new records to tblAccuracy using frmRegister. Under specific
conditions I need to append the current record from frmRegister into
tblClearance. I was thinking of placing the code on the form's BeforeUpdate
event so that it will fire whether the user closes the form or attempts to
create another record.

i.e.

if field 'CheckType='A' or 'B' or 'C' then

open the tblClearance recordset
check if there's an ID number equal to the ID of the currently displayed
record on frmRegistration
if not, prompt the user to run an action query to append the current record
into tblClearance
Close the recordset

I've tried saved queries thinking of speed, but keep getting errors. I want
to do this efficiently so instead of messing around and maybe (..?!)
stumbling on a solution, can anyone tell me the correct way to approach
this. I'm confident I'd make an inefficient job of it, if left to my own
devices.

Many TIA,

Paul.
Nov 12 '05 #1
2 6511
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may wish to re-think your solution - having 2 tables of the same
data is redundant, which is a no-no in relational database design.

But, to specifically answer your question:

You should use the Form_AfterUpdate event procedure to run the append
query - 'cuz the form's AfterUpdate event only runs after a record has
been saved. Here's how I usually do it (VBA example - untested):

' Declaration section
Dim m_lngRecordID As Long
- -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me!CheckType='A' or Me!CheckType='B' or Me!CheckType='C' Then
' Remember the current record's unique ID
m_lngRecordID = Me!CustomerID
Else
m_lngRecordID = 0
End IF

' ... other code, as required ...

End Sub

Private Sub Form_AfterUpdate()

If m_lngID <> 0 Then
' Get the ID of the last saved record,
' modify the append query & execute it.

Const QRY_APPEND = "qryAppendCustomerSales"

Dim db As DAO.Database
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set qd = db.QueryDefs(QRY_APPEND)
qd.Parameters("myID") = m_lngRecordID
qd.Execute dbFailOnError

On Error Resume Next
Set qd = Nothing
Set db = Nothing
End If

End Sub

The append query "qryAppendCustomerSales" looks like this:

PARAMETERS myID Long;
INSERT INTO tblSalesHistory (ID, SalesDate, SalesAmount)
SELECT ID, SalesDate, SalesAmt
FROM tblCurrentSales
WHERE ID = myID

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP/DNtoechKqOuFEgEQJs4gCfdtTvy0vIUtH4oHhwhXPxJSqgqssA oPgT
IICDtLYF0qoNaJXVsmBdkKrz
=HGBK
-----END PGP SIGNATURE-----
Paul Wagstaff wrote:
Hi there

I have 2 tables: tblAccuracy & tblClearance

Users add new records to tblAccuracy using frmRegister. Under specific
conditions I need to append the current record from frmRegister into
tblClearance. I was thinking of placing the code on the form's BeforeUpdate
event so that it will fire whether the user closes the form or attempts to
create another record.

i.e.

if field 'CheckType='A' or 'B' or 'C' then

open the tblClearance recordset
check if there's an ID number equal to the ID of the currently displayed
record on frmRegistration
if not, prompt the user to run an action query to append the current record
into tblClearance
Close the recordset

I've tried saved queries thinking of speed, but keep getting errors. I want
to do this efficiently so instead of messing around and maybe (..?!)
stumbling on a solution, can anyone tell me the correct way to approach
this. I'm confident I'd make an inefficient job of it, if left to my own
devices.

Many TIA,

Paul.


Nov 12 '05 #2
Thanks for that...I've tried your code today with sucess! The table
structure here is poor, I know, but will have to stay 'as is' at least for
now. The client operates in a v. volatile environmernt & it'd be a bugger to
normalise these 2 tables properly.

Thanks again!

"MGFoster" <me@privacy.com> wrote in message
news:U4******************@newsread1.news.pas.earth link.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may wish to re-think your solution - having 2 tables of the same
data is redundant, which is a no-no in relational database design.

But, to specifically answer your question:

You should use the Form_AfterUpdate event procedure to run the append
query - 'cuz the form's AfterUpdate event only runs after a record has
been saved. Here's how I usually do it (VBA example - untested):

' Declaration section
Dim m_lngRecordID As Long
- -----
Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me!CheckType='A' or Me!CheckType='B' or Me!CheckType='C' Then
' Remember the current record's unique ID
m_lngRecordID = Me!CustomerID
Else
m_lngRecordID = 0
End IF

' ... other code, as required ...

End Sub

Private Sub Form_AfterUpdate()

If m_lngID <> 0 Then
' Get the ID of the last saved record,
' modify the append query & execute it.

Const QRY_APPEND = "qryAppendCustomerSales"

Dim db As DAO.Database
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set qd = db.QueryDefs(QRY_APPEND)
qd.Parameters("myID") = m_lngRecordID
qd.Execute dbFailOnError

On Error Resume Next
Set qd = Nothing
Set db = Nothing
End If

End Sub

The append query "qryAppendCustomerSales" looks like this:

PARAMETERS myID Long;
INSERT INTO tblSalesHistory (ID, SalesDate, SalesAmount)
SELECT ID, SalesDate, SalesAmt
FROM tblCurrentSales
WHERE ID = myID

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP/DNtoechKqOuFEgEQJs4gCfdtTvy0vIUtH4oHhwhXPxJSqgqssA oPgT
IICDtLYF0qoNaJXVsmBdkKrz
=HGBK
-----END PGP SIGNATURE-----
Paul Wagstaff wrote:
Hi there

I have 2 tables: tblAccuracy & tblClearance

Users add new records to tblAccuracy using frmRegister. Under specific
conditions I need to append the current record from frmRegister into
tblClearance. I was thinking of placing the code on the form's BeforeUpdate event so that it will fire whether the user closes the form or attempts to create another record.

i.e.

if field 'CheckType='A' or 'B' or 'C' then

open the tblClearance recordset
check if there's an ID number equal to the ID of the currently displayed
record on frmRegistration
if not, prompt the user to run an action query to append the current record into tblClearance
Close the recordset

I've tried saved queries thinking of speed, but keep getting errors. I want to do this efficiently so instead of messing around and maybe (..?!)
stumbling on a solution, can anyone tell me the correct way to approach
this. I'm confident I'd make an inefficient job of it, if left to my own
devices.

Many TIA,

Paul.

Nov 12 '05 #3

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

Similar topics

1
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to use a make table query to pull the last transactionID, so I can use an append query to reset the transactionID to the next...
1
by: Paul | last post by:
I could really use some help please. SETUP: I have a table called "ProductTable" I have a query called "ProductQuery" based on ProductTable I have a form Called "ProductMF" based on...
24
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a...
2
by: jodyblau | last post by:
I am trying to change the recordset that my form uses, but when I requery my form, all of the textboxes display #Name? Here is what I am trying to do: The user enters a search term in a textbox...
3
by: Bob | last post by:
I need to get several recordset for which I'm opening a datareader like so... OleDbCommand rsA = new OleDbCommand("Select * from Authors",cnAccess); OleDbDataReader drA = rsA.ExecuteReader();...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
11
by: BeckR | last post by:
Hello - Thanks for reading my post. I am a newbie when it comes to VBA programming, but have managed to do what I need to do, until now. I have an Access 2000 database (running WinXP Pro...
10
by: MeeMee | last post by:
Hi I have a problem appending data into an oracle table from access. I imported the new data from an excel sheet into a table in access and useed an append query to add the data into a linked...
5
by: slickdock | last post by:
I need to break my query into 3 groups: First 60 records (records 1-60) Next 60 records (records 61-121) Next 60 records (records 122-182) Of course I could use top values 60 for the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.