[英]MS Access: Pass Value from Form Textbox to Another Form Combo Box on a New Record?
Okay, bare with me, this is a really hard question to describe, and I'm fairly new to VBA.好吧,对我来说,这是一个很难描述的问题,而且我对 VBA 还很陌生。
I have a 'Customer Form' with a Command Button to create a New Order in an 'Order Form'.我有一个带有命令按钮的“客户表单”,用于在“订单”中创建新订单。 I can get the button to Open the 'Order Form' to a New Record, but I can't get it to pass the 'CustomerID' to the 'Order Form' Combo Box 'CustomerID'.
我可以获得将“订单”打开到新记录的按钮,但无法将“CustomerID”传递给“订单”组合框“CustomerID”。 I need the 'Order Form' to auto-populate with information from the 'Customer Form'.
我需要“订单”来自动填充“客户表单”中的信息。
Order Form:订单:
The Customer Combo Box shows the Customer Full Name, but is bound to the CustomerID客户组合框显示客户全名,但绑定到客户 ID
Here's the VBA Code I have tried:这是我尝试过的 VBA 代码:
Private Sub BtnNewOrder_Click()
DoCmd.OpenForm FormName:="Order Form", View:=acNormal, OpenArgs:=Me.CustomerID.Value
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
Me.CustomerID = Me.OpenArgs
End If
End Sub
I get the following error:我收到以下错误:
I've been browsing the web for days without any luck.几天来,我一直在浏览 web,但没有任何运气。 I'm sure this question has been asked before, but I haven't been able to find the right solution.
我确定这个问题之前已经被问过,但我一直无法找到正确的解决方案。 Feel free to simply point me in the right direction.
随意简单地指出我正确的方向。
You have to use the forms on-load event.您必须使用 forms 加载事件。 The on open event is too soon.
开放事件为时过早。
On Open event - allows testing of controls and values - you can set cancel = true and form will not load.在 Open 事件上 - 允许测试控件和值 - 您可以设置 cancel = true 并且不会加载表单。 So, on open is for checking/testing if you want to let the form open, based on custom code that checks things.
因此,on open 用于检查/测试是否要让表单打开,基于检查事物的自定义代码。 If you don't want the form to load - you can set Cancel = true.
如果您不想加载表单 - 您可以设置 Cancel = true。
On Load event: Here is where your setup code, set variables, possible set controls etc. is to occur. On Load 事件:这里是您的设置代码、设置变量、可能的设置控件等发生的地方。 So you can't modify controls in on-open - too soon of a event, but you CAN modify the forms controls and values in the on-load event.
因此,您不能在打开时修改控件 - 事件太早,但您可以在加载事件中修改 forms 控件和值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.