473,507 Members | 5,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to append data from one table to a another table upon the deletion of the first t

9 New Member
i have two tables i.e tblSalesMAIN and tblSalesMAIN1. the later is a duplicate of the formar. i have a data entry form bounded to tblSalesMAIN, i have also created a continuose form from tblSalesMAINtblSales and droped it on the data entry form i have created. My goal here is to have all the data i enter into tblSalesMAIN from the bounded form show up in the continuose form but, have it all cleared from tblSalesMAIN and the continuouse form to make room for new entry.
Now, i would like to have all the information i clear from tblSales through a button click event be appended to the duplicated table tblSalesMAIN1.

I have tried all that i know how to do, but to No avail.Below is my the code i am working on. i really your help. Thank you in advance.

Dim dbs As DAO.Database
set dbs = Current.OpenRecordset("SELECT * FROM [tblSalesMAIN]")
dbs.Execute " INSERT INTO tblSalesMAIN1 " _
& "SELECT * "
& "FROM [tblSalesMAIN];"
dbs.Close



If MsgBox("You are about to delete all records. Are you sure?", _
vbQuestion + vbYesNo) = vbNO Then
Exit Sub
End If
strSQL = "DELETE*FROM tblSalesMAIN subform2"
DoCmd.SetWarnings False
DoCmd.RunSQL
DoCmd.SetWarnings True
Me.Requery
Me.Refresh

End Sub


Private Sub cmdd_Click()
DoCmd.GoToRecord , "", acNewRec
Me.Refresh

End Sub
Jul 4 '18 #1
13 1568
PhilOfWalton
1,430 Recognized Expert Top Contributor
Welcome to Bytes

Are you saying that you have a Sales entry form, and a continuous form showing a resume of the past sales entries?

When you press a Command Button on your main form after entering a new sale, you want that entry to show up on the continuous form, and have a blank Sales Entry form, ready for the next entry?

Phil
Jul 4 '18 #2
inte
9 New Member
Thanks a lot Phill. I have commented some adjustment I have made to the code, but I am still not getting it right. I hope code I have added and the zipped copy of the portion of my project will give you guys some clarification to be able to assist me.


Private Sub cmdClear_Click()
'Dim dbs As DAO.Database
'set dbs = Current.OpenRecordset("SELECT * FROM [tblSalesMAIN]")
'dbs.Execute " INSERT INTO tblSalesMAIN1 " _
'& "SELECT * "
'& "FROM [tblSalesMAIN];"
'dbs.Close


'INSERT INTO tblSalesMAIN1 [(salesID[, salesTime[, salesDate[, unitPrice[, quantity[, cashTendered[, change[, price]]]]]]])] SELECT ([tblSalesMAIN.SalesID[, tblSalesMAIN.salesTime[, tblSalesMAIN.salesDate[, tblSalesMAIN.unitPrice[, tblSalesMAIN.quantity[, tblSalesMAIN.cashTendered[, tblSalesMAIN.change[, tblSalesMAIN.price]]]]]]])

'DoCmd.RunQuery


If MsgBox("You are about to delete all records. Are you sure?", _
vbQuestion + vbYesNo) = vbNO Then
Exit Sub
End If
strSQL = "DELETE*FROM tblSalesMAIN subform2"
DoCmd.SetWarnings False
DoCmd.RunSQL
DoCmd.SetWarnings True
Me.Requery
Me.Refresh

End Sub


Private Sub cmdd_Click()
DoCmd.GoToRecord , "", acNewRec
Me.Refresh

End Sub
Attached Files
File Type: zip TAG Manager Assistant.zip (40.8 KB, 76 views)
Jul 4 '18 #3
PhilOfWalton
1,430 Recognized Expert Top Contributor
I can't help unless you answer the questions.

Phil
Jul 4 '18 #4
inte
9 New Member
Are you saying that you have a Sales entry form? Yes

a resume of the past sales entries? No

When you press a Command Button on your main form after entering a new sale, you want that entry to show up on the continuous form, and have a blank Sales Entry form, ready for the next entry? Yes but i have done that already.

what i want to have all of the individual sales have added and are already showing in the table named tblSaleMAIN to be appended to another table named tblSalesMAIN1.
Jul 4 '18 #5
twinnyfo
3,653 Recognized Expert Moderator Specialist
A more important question is why would you want to do this. If the tables are identical, then don’t waste your time copying and deleting—this can cause problems if there are any errors. Instead, have a Yes/No field “Archived” that is set to True when you want to archive the records. Then, filter the second form by only those records that have been archived.

Trust me on this one: I had a design similar to yours in the past and it was nothing bu headaches. The recommended solution will help you in the long run.

Hope this hepps!
Jul 4 '18 #6
PhilOfWalton
1,430 Recognized Expert Top Contributor
So what are you going to use tblSalesMAIN1 for? Is this supposed to be a record of ALL your sales?

Phil
Jul 4 '18 #7
inte
9 New Member
Yes tblSalesMAIN1 is suppose to be a record of all sales
Jul 4 '18 #8
inte
9 New Member
I honestly would love to give your suggestion a try. But I do not understand you well enough. Also I am very limited with regards to vba
Jul 4 '18 #9
PhilOfWalton
1,430 Recognized Expert Top Contributor
Twinnyfo is spot on. My thoughts exactly that the second table is not required.

However, the way you have your table set up, there is nothing to link the individual sales together such as an OrderID. Your way, each sale is for a single item (unspecified), and one sale has absolutely no relationship to the next sale. So, the subform seems a bit superfluous.

Phil
Jul 4 '18 #10
inte
9 New Member
I agree. Ok let me try to relate the two table with an OrderID. I will let you guys know of the outcome.

Thanks a lot to you all
Jul 4 '18 #11
inte
9 New Member
Guys, I would very much love to have fresh ideas from any one. I have tried the about suggestion but it isn't good enough for my purpose, since the portion of my project in discussion here belongs a very big project, I am finding it difficult integrating it with the other parts of the project

if anyone could at least show me how to get my model to work I would be very grateful.
Thank you all in advance
Jul 4 '18 #12
PhilOfWalton
1,430 Recognized Expert Top Contributor
OK. Add a Yes/No field called "Archives" to your TblSalesMain (Default Value = 'No')

On the main form, set Allow Deletions & Allow Edits to false

Change the RecordSource of both forms to
Expand|Select|Wrap|Line Numbers
  1. SELECT tblSalesMAIN.*
  2. FROM tblSalesMAIN
  3. WHERE (((tblSalesMAIN.Archived)=False));
  4.  
So we can only see non-archived records.

Change the code on the "cmdClear" to

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdClear_Click()
  5.  
  6.     Dim MyDb As DAO.Database
  7.     Dim RstSales As Recordset
  8.     Dim StrSQL As String
  9.  
  10.     StrSQL = "SELECT TblSalesMain.* FROM TblSalesmain"
  11.  
  12.     Set MyDb = CurrentDb
  13.     Set RstSales = MyDb.OpenRecordset(StrSQL)
  14.  
  15.     With RstSales
  16.         Do Until .EOF
  17.             .Edit
  18.             !Archived = True
  19.             .Update
  20.             .MoveNext
  21.         Loop
  22.         .Close
  23.         Set RstSales = Nothing
  24.     End With
  25.  
  26. End Sub
  27.  
This sets the Archived field to 'yes' for all records.

Note that at the top of every module you ever write, you should have
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
If, when you compile the code, the Option Explicit is missing, the compiler will not warn of errors (Missing definitions particularly)

Phil
Jul 4 '18 #13
inte
9 New Member
I appreciate all of the help you guys have offered me. I am proud to inform you that, after a bit of tweaking here and there, I have had take worry taken away, thanks you guys.
Jul 6 '18 #14

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

Similar topics

4
13451
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
0
2244
by: Rob Meade | last post by:
Hi all, Ok - I need to plonk a repeater in my form which is using a template (table and series of web user controls)...as a result I have something like this (short version) <table> <tr>...
6
1632
by: Reggie | last post by:
Hi and TIA. I have an OleDB connection to an Access db which I connect to and place data from a table into a recordset. What I want to do is copy this recordset to an SQL table. I have no...
5
5345
by: Michael C via AccessMonster.com | last post by:
Hello, I have a table that I am appending 3 seperate tables into. My main problem is that each time I append the data, it simply adds to the data already there. That might sound ok, except that...
3
3355
by: Darin | last post by:
This is something that on the surface seems like it should be simple, but I can't think of a way to do this. I have a table that is a list of "jobs", which users create and use. It has a single...
11
2138
by: LiDongning | last post by:
I have a situation here: every month there will be a table (with 3200+- entries) that should be appended to a Year-to-Date table. I appended the second month's live table to the accumulative...
11
7721
by: KingKen | last post by:
I am trying to export some values from a table in my database to a text file then have these values imported and apprnded to another copy of the same database table the same table in another location...
1
1980
by: Katie Howard | last post by:
Hi, I’m just starting a database that will contain historical data of all the conferences that our employees have attended over the years. I have 3 tables (Employees, Conferences, and the 3rd is...
8
2429
by: Sandra Walsh | last post by:
Hello - I have a local table in my database called t_CompanyData that holds a subset of the fields in another table called dbo_INT_AUX_LISTING. dbo_INT_AUX_LISTING is a linked table via an...
1
1608
by: jduehmig | last post by:
I'm hoping someone can help me out with this. I think the answer is pretty straightfoward but I would rather ask first rather than end up corrupting live data. I used the SQL Server Migration...
0
7221
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
7109
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
7313
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
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
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
5619
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
5039
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
3190
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
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.