PC Review


Reply
Thread Tools Rate Thread

Add records to to 2 tables

 
 
Wahab
Guest
Posts: n/a
 
      29th Jan 2009
Good Day
I have a continuous bound form to table ‘tSalesDetails’, normally there will
be 7 to 10 records for every Invoice. This form is working fine, adding
records to bound table. But for some reports I use to re-enter those sales in
another table (tSalesReports), this is duplicate job and I want to avoid this
by writing code I tried with the following but not adding to that table pls
check my code
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tSalesReports WHERE
InvoiceNo = " & InvoiceNo & "")
Do Until rst.EOF
If Not rst.EOF Then
rst.Edit
Else
rst.AddNew
End If
rst!InvoiceNo = InvoiceNo
rst!ProductCode=ProductID
rst!Cartons = Quantity
rst!ItemPrice = Price
rst!Sale = ProductSales
rst.Update
rst.MoveNext
Loop
rst.Close

Pls help me
thanks and regards
wahab
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      29th Jan 2009
Why are you trying to store the data redundantly? Can't you just use a query
for your report?

If you have a legitimate reason (which I doubt), using a query will almost
always be signicantly faster than use VBA.

Dim strSQL As String

strSQL = "UPDATE tSalesDetails LEFT JOIN tSalesReport " & _
"ON tSalesDetails.InvoiceNo = tSalesReport.InvoiceNo " & _
"SET tSalesReport.InvoiceNo = tSalesDetails.InvoiceNo, " & _
"tSalesReport.ProductCode = tSalesDetails.ProductCode, " & _
"tSalesReport.Cartons = tSalesDetails.Quantity, " & _
"tSalesReport.ItemPrice = tSalesDetails.Price, " & _
"tSalesReport.Sale = tSalesDetails.ProductSales"

CurrentDb.Execute strSQL, dbFailOnError


That will add new records to tSalesDetails for invoices that don't already
exist, and update ones that do.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Wahab" <(E-Mail Removed)> wrote in message
newsE3E8E4E-6F83-4F9A-8FC4-(E-Mail Removed)...
> Good Day
> I have a continuous bound form to table 'tSalesDetails', normally there
> will
> be 7 to 10 records for every Invoice. This form is working fine, adding
> records to bound table. But for some reports I use to re-enter those sales
> in
> another table (tSalesReports), this is duplicate job and I want to avoid
> this
> by writing code I tried with the following but not adding to that table
> pls
> check my code
> Set rst = CurrentDb.OpenRecordset("SELECT * FROM tSalesReports WHERE
> InvoiceNo = " & InvoiceNo & "")
> Do Until rst.EOF
> If Not rst.EOF Then
> rst.Edit
> Else
> rst.AddNew
> End If
> rst!InvoiceNo = InvoiceNo
> rst!ProductCode=ProductID
> rst!Cartons = Quantity
> rst!ItemPrice = Price
> rst!Sale = ProductSales
> rst.Update
> rst.MoveNext
> Loop
> rst.Close
>
> Pls help me
> thanks and regards
> wahab



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy selected records from two tables to two new tables alhotch Microsoft Access 2 1st Feb 2010 12:03 AM
records from tables =?Utf-8?B?amphY29i?= Microsoft Access Queries 1 12th Jul 2007 05:12 PM
Appending Records from Linked Tables to the *Real* Linked Tables tbl Microsoft Access Queries 2 22nd Jun 2006 01:42 AM
How to join 2 Access tables to return ALL records from both tables =?Utf-8?B?SkVS?= Microsoft Access Queries 4 12th Jan 2006 12:28 AM
Macro to compare records of 2 tables and create new records on any change Joe Microsoft Access Macros 0 1st Apr 2005 10:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:20 PM.