MS Access-将数据从一个子窗体传递到另一个窗体



我有一个用于搜索记录的主窗体(Form1(,该窗体的子窗体包含所有搜索到的记录。在Form1中无法编辑或添加数据。

我希望能够从子窗体中单击一条记录,然后单击一个按钮,将该特定记录复制到一个单独的窗体(Form2(。我想这样做,这样用户就不必手动将数据从Form1子表单复制并粘贴到Form2。

我尝试过连续形式,但它的最大宽度不够。我是Access的新手,正在尝试找到解决这个问题的方法。有人能提出这样做的方法吗。TIA-

有几种方法可以做到这一点,我不知道正确的技术术语,但我希望它能有所帮助;

选项1:从子窗体插入到与主窗体关联的相关表

示例:表单数据:tbl客户

子表单数据:tbl潜在客户

因此,要将子表单中的数据添加到表单中,只需尝试以下操作:

public sub Insert

Dim strSQL as string
Dim strPotentialCustomerName as string
Dim strPotentialCustomerKey as string

strPotentialCustomerName  = me.subform.PotentialCustomerName
strPotentialCustomerKey = me.subform.PotentialCustomerKey
strSQL = "Insert into tblCustomer (CustomerName,PotentialCustomerKey) Values ('"& strPotentialCustomerName &"','"& strPotentialCustomerKey  &"')"

call Currentdb.execute(strSQL,dbseechanges)

'--- BEWARE : In the mainform the new record is not automaticaly show, so you need an event to handle this.

end sub

选项2:直接使用父级将其插入主窗体

尝试到达相关对象,如:

从您的子表单:

me.parent!CustomerName = mySubform.PotentialCustomerName

希望这能让你朝着正确的方向前进。祝你一切顺利!

相关内容

最新更新