Access 2007 VBA DoCmd.Close 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13867679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access 2007 VBA DoCmd.Close not working
提问by user1860787
I know this is probably a stupid question, but you know what they say. I have VBA in an Access Database with commands for On Click. Essentially it is a form with a combo box and timestamp for user login. Once the button is clicked a data entry form will load dependent upon which name is selected from the Combo Box. I would like for the Login Form to close once the data entry form has opened. The problem is that no matter where I put the DoCmd.Close the stupid form won't CLOSE!
我知道这可能是一个愚蠢的问题,但你知道他们说什么。我在 Access 数据库中有 VBA,其中包含用于单击的命令。本质上,它是一个带有组合框和用户登录时间戳的表单。单击按钮后,将根据从组合框中选择的名称加载数据输入表单。我希望在数据输入表单打开后关闭登录表单。问题是无论我把 DoCmd.Close 放在哪里,愚蠢的表单都不会关闭!
In case it matters this form is set to open automatically when a user opens the database.
万一这个表单被设置为在用户打开数据库时自动打开。
Below is the VBA for the Event Procedure associated with the button.
下面是与按钮关联的事件过程的 VBA。
Option Compare Database
Private Sub TimeInButton_Click()
Dim strLoginForm As String
If Me.AgentCombo = "Amber" Then
strForm = "frmCustomersAmber"
ElseIf Me.AgentCombo = "Amanda" Then
strForm = "frmCustomersAmanda"
ElseIf Me.AgentCombo = "Brett" Then
strForm = "frmCustomersBrett"
ElseIf Me.AgentCombo = "Marcus" Then
strForm = "frmCustomersMarcus"
ElseIf Me.AgentCombo = "Terrah" Then
strForm = "frmCustomersTerrah"
End If
'------------------------------------------------------------
' TimeInButton_Click
'
'------------------------------------------------------------
On Error GoTo TimeInButton_Click_Err
On Error Resume Next
DoCmd.GoToRecord , "", acNewRec
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
DoCmd.OpenForm strForm
TimeInButton_Click_Exit:
Exit Sub
TimeInButton_Click_Err:
MsgBox Error$
Resume TimeInButton_Click_Exit
End Sub
回答by mwolfe02
DoCmd.Close takes optional arguments that will make it much more reliable. For example,
DoCmd.Close 采用可选参数,使其更加可靠。例如,
DoCmd.Close acForm, "MyFormName"