如何在删除第一个t时将数据从一个表附加到另一个表 [英] How to append data from one table to a another table upon the deletion of the first t

查看:59
本文介绍了如何在删除第一个t时将数据从一个表附加到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,即tblSalesMAIN和tblSalesMAIN1。后者是formar的副本。我有一个数据输入表格绑定到tblSalesMAIN,我还从tblSalesMAINtblSales创建了一个连续的表单,并在我创建的数据输入表单上下载了它。我的目标是让我从有界表单输入tblSalesMAIN的所有数据以连续形式显示,但是,从tblSalesMAIN和continuouse表单中清除所有数据,以便为新条目腾出空间。

现在,我希望通过按钮点击事件将我从tblSales清除的所有信息附加到重复的表tblSalesMAIN1。


我已经尝试了所有我知道怎么做的信息,但无济于事。下面是我正在处理的代码。我真的很乐意提前谢谢。


Dim dbs作为DAO.Database

set dbs = Current.OpenRecordset(" SELECT * FROM [tblSalesMAIN]")

dbs.Execute INSERT INTO tblSalesMAIN1" _

& SELECT *

& FROM [tblSalesMAIN];"

dbs.Close



如果MsgBox(您即将删除)所有记录。你确定吗?",_

vbQuestion + vbYesNo)= vbNO然后

退出Sub

结束如果

strSQL =" DELETE * FROM tblSalesMAIN subform2"

DoCmd.SetWarnings False

DoCmd.RunSQL

DoCmd.SetWarnings True < br $>
Me.Requery

Me.Refresh


End Sub



Private Sub cmdd_Click()

DoCmd.GoToRecord,",acNewRec

Me.Refresh


End Sub

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

推荐答案

欢迎来到字节


您是说您有一份销售报名表,还有一份连续表格,显示简历过去的销售条目?


当您在输入新的销售后按下主表单上的命令按钮时,您希望该条目显示在连续表单上,并且具有空白的销售Ë ntry表格,准备下一个条目?


Phil
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


非常感谢Phill。我已经对代码做了一些调整,但我仍然没有做到正确。我希望我添加的代码和项目部分的压缩副本将给你们一些澄清,以便能够帮助我。



Private Sub cmdClear_Click()

''Dim dbs作为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



如果MsgBox(你即将删除所有记录。你确定吗?,_

vbQuestion + vbYesNo)= vbNO那么

退出Sub

结束如果

strSQL =" DELETE * FROM tblSalesMAIN subform2"

DoCmd.SetWarnings False

DoCmd.RunSQL

DoCmd.SetWarnings True

Me.Requery

Me.Refresh


结束子


私人子cmdd_Click()

DoCmd.GoToRecord,",",acNewRec

Me.Refresh


结束子





$ b
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
附加文件
< a href =https://bytes.com/attachments/attachment/9518d1530704663/tag-manager-assistant.zip> TAG Manager Assistant.zip (40.8 KB,18 views)
Attached Files
TAG Manager Assistant.zip (40.8 KB, 18 views)


除非你回答问题,否则我无能为力。


Phil
I can''t help unless you answer the questions.

Phil


这篇关于如何在删除第一个t时将数据从一个表附加到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆