尝试从另一个表单引用文本框的访问 VBA [英] Access VBA trying to reference a textbox from another form

查看:60
本文介绍了尝试从另一个表单引用文本框的访问 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Access VBA,并且正在尝试修改现有代码以添加一个弹出框.这个弹出框是另一种表单,当用户点击这个表单上的按钮时,我想要填充基本表单上的一个文本框.之后弹出窗口消失,然后我需要从基本表单上的文本框中访问该值.

I'm using Access VBA, and I'm trying to modify existing code to add a popup box. This popup box is another form, and when a user clicks on a button on this form, I want a textbox on the base form to be populated. After that the popup disappears and then I need to access that value from the textbox on the base form.

顺序应该是这样的:
1) 基本表单按钮单击调用模态弹出窗口
2)单击弹出窗口中的按钮将值保存到基本表单的文本框,然后返回控制权.
3) 基础形式然后使用这个值做某事.

The sequence should be like this:
1) Base form button click calls modal popup
2) Click in button on popup saves value to base form's textbox, then returns control.
3) Base form then uses this value to do something.

我有一些代码,但它不能正常工作.任何人都可以看到这里缺少什么并帮助我纠正吗?

I have some code, but its not working properly. Can anyone see whats missing here and help me correct?

基础表格

Sub base()
    DoCmd.OpenForm "PaperType", , , , , acDialog

    MsgBox Me.TheAnswer           'This line gives a null error
End Sub

弹出表单

Private Sub btnRolls_Click()
    'Me.Tag = 1
    Forms!ReceiptDetail_sfrm!TheAnswer = 1
    Me.Visible = False
End Sub

Private Sub btnSheets_Click()
    'Me.Tag = 4
    Forms!("ReceiptDetail_sfrm").TheAnswer = 4
    Me.Visible = False
End Sub

推荐答案

你可以这样做,你可能需要这样的东西:

You can do it that way, you probably need something like:

私有子 btnRolls_Click()Forms!ReceiptDetail_sfrm!TheAnswer = 1Forms!ReceiptDetail_sfrm.RefreshMe.Visible = 错误结束子

Private Sub btnRolls_Click() Forms!ReceiptDetail_sfrm!TheAnswer = 1 Forms!ReceiptDetail_sfrm.Refresh Me.Visible = False End Sub

我已经做了很多次你正在做的事情.我现在不在工作中检查我的代码作为示例,但它是可行的.

I've done what you're doing many times. I'm not at work to check my code right now for an example, but it's doable.

这篇关于尝试从另一个表单引用文本框的访问 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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