微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

我希望能够单击子表单中的记录并单击按钮,将该特定记录复制到单独的表单 (Form2)。我想这样做,以便用户不必手动将数据从 Form1-subform 复制并粘贴到 Form2。

我尝试过连续表格,但它的最大宽度不够。我是 Access 的新手,并试图找出解决此问题的方法。 任何人都可以建议一种方法来做到这一点。 TIA

解决方法

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

选项 1:从子表单插入到与主表单相连的相关表格

示例: 表单数据:tblCustomer

子表单数据:tblPotentialCustomer

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

    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 : 直接使用 parent 将其插入到主表单

尝试到达相关对象,例如:

来自您的子表单:

me.parent!CustomerName = mySubform.PotentialCustomerName

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。