访问打开表单作为对话框停止运行代码

问题描述 投票:0回答:2

我有几个例子,我想在一个dialaog和经销商,以打开一个表格填写的字段。例如:

AddClients和AddClientContacts我有一个对话框,既了addClient和AddClientContact

当了addClient对话框我想有一个按钮,打开对话框AddClientContact和经销商填写ID字段。

我的代码工作就开了,我的代码工作来复制数据,但开放后的代码不工作,直到对话框关闭。 (和VBA编辑器,你可以看到它仍在运行)

我已经通过宏的OpenForm然后RunCode和VBA DoCmd.OpenForm尝试,但每次有同样的问题。

这是正常的对话框的行为?有没有一种方法,使代码运行的公开对话命令后?

只是寻找一个简单的方法来打开,然后填充字段。这是VBA我目前的样子:

Private Sub btn_AddClientContacts_Click()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "frm_ADDClientContact", acNormal, , , acFormAdd, acDialog
Forms!frm_ADDClientContact!FK_CC_Client_ID = Forms!frm_ADDClients!Client_ID
End Sub

谢谢,明天

vba ms-access dialog access-vba ms-access-2010
2个回答
1
投票

这是正常的对话框的行为?

确实。

移动你继续码的对话形式的OnOpen事件或从那里调用它。


0
投票

不要运行,它的浪费和危险的停止代码。使用事件系统接口。

我这个代码的原作者,与复制要求为你的自由与用途。

Option Compare Database

' VBA Access/Excel 2016 Class: Form Instance Callback System
' Class Name: IDialogConnection

' Purpose: Create Dialogs/Pop-ups, from form instances,
'          and monitor lifecycle and process the dialog's data
'          with event callbacks (rather than waiting/sleeping).

' USAGE:

' (1) Create an instance of this class within your callee form.
' Public CallbackConnection as New IDialogConnection

' (2) Use the CallbackConnection.Methods in your callee form,
' to notify the caller of your hide/show/action operations through
' events:
'
' Public Sub Show()
'   CallbackConnection.NotifyShow
' End Sub
'
' Private Sub HideButton_Click()
'   CallbackConnection.NotifyHide
' End Sub
'
' Private Sub ActionButton_Click()
'   CallbackConnection.NotifyAction(0, SomeFormData)
' End Sub
'
' You can have as many actions as you want, and you can modify
' The data: 'SomeFormData' from within the event handler.

' (3) Create an instance of your callee form in the caller's form.
' Dim Callee as new Form_*?*

' (4) Create an Event Hook Handler in your caller's form.
' Public WithEvents DialogConnection as IDialogConnection

' (5) Connect the DialogConnection Events to your caller's form,
' the same way you Connect to other form/class events.

' (6) In the Sub Form_Load() of your caller, establish the connection:
' Set DialogConnection = Callee.CallbackConnection

Public Event OnShow()
Public Event OnHide()

Public Event OnAction(id As Integer, ByRef data As Variant)

Public Sub NotifyShow()
    RaiseEvent OnShow
End Sub

Public Sub NotifyHide()
    RaiseEvent OnHide
End Sub

Public Sub NotifyAction(id As Integer, ByRef data As Variant)
    RaiseEvent OnAction(id, data)
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.