简体   繁体   English

MS Access:将值从表单文本框传递到新记录上的另一个表单组合框?

[英]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'.我需要“订单”来自动填充“客户表单”中的信息。

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.

相关问题 MS Access VBA组合框打开一个对话框,而不是从窗体中获取组合框值 - MS Access VBA Combo Box opens a dialog instead of taking the combo box value from the form MS Access 将表单中的值复制到另一个表单文本框中 - MS Access Copying value from a form into another form text box 女士访问列表框-双击传递参数到新表格 - Ms Access List Box - Pass parameter on Double click to a new form 将条件从组合框传递到Access 2010中的另一个组合框 - Pass criteria from a combo box to another combo box in access 2010 通过在列表下拉组合框中选择它来访问 VBA 代码到 go 到另一个表单上的特定记录 - Access VBA code to go to a specific record on another form via selecting it in a list drop down combo box 基于当前字段值的MS Access表单组合框行源 - MS access form combo box row source based on current field value 根据组合框内容选择MS Access表单中的记录 - Selecting records in MS Access form based on combo box contents 在 ms-Access 中使用组合框创建搜索表单 - Creating a Search Form using a Combo Box in ms-Access 访问:尝试打开一个表单并使用另一个表单中的值填充文本框 - Access: trying to open a form and populate a textbox with the value from another form MS Access 从子表单的组合框中选择下拉菜单后,在主表单中填写 ID - MS Access Fill in ID in the Main Form after select drop down from combo box in Subform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM