Access 2007将字段设置为对话框中的选择

时间:2009-10-01 15:40:03

标签: ms-access vba ms-access-2007

我想将字段设置为从对话框中的网格中选择的值。我正在使用Access 2007。

在WinForms中我会:

  • 创建子表单
    • 为数据创建网格
    • 为所选项目添加属性
  • 在父表格中
    • 添加按钮以打开表单
    • 成功的对话框结果从属性中获取所选项目
    • 更新对象
    • 坚持活动
  • 在父编辑上
    • 在子网格中设置选定的值

在Access 2007表单中是否可以这样?我有一个包含子记录的多项目表单。我可以选择一个并将其返回给父母吗?另一方面,我可以在编辑时默认选定的项目吗?

人们如何在Access中解决这个问题?

1 个答案:

答案 0 :(得分:1)

这是一种假设子表单是模态的模式。

在您的父表单中

Private Sub cmdOpenChild_Click()
    DoCmd.OpenForm "ChildDialog", acNormal, , , , acDialog, "Info for child"

    'This line will block further code execution until child form is hidden or closed.  
    MsgBox Forms.Item("ChildDialog").Controls.Item("SomePropertyOrControl").Value

    DoCmd.Close acForm, "ChildDialog"
end sub

在子表单中有一个关闭按钮,实际上只隐藏表单。

Private Sub cmdClose_Click()
    'hide the form instead of closing it to return control to caller.
    Me.Visible = False
End sub