【发布时间】:2018-07-07 05:38:53
【问题描述】:
在 Access 2016 Switchboard 上,我将表单后面的宏转换为 VBA,但无法编译。我发现的创可贴解决方案是将 .Value 添加到 TempVars.Add "CurrentItemNumber", ItemNumber 并更改 Call Argument 和 "()" 的两个实例 到 调用 Eval(Argument & "()")。这样就解决了编译错误。
然后,我在 Switchboard 中添加了另一个按钮“报告菜单”,但是当我单击新按钮时出现此错误。
当我单击“调试”时,它会突出显示这一行 TempVars.Add "SwitchboardID", Argument。当我将 .Value 添加到这一行的末尾 TempVars.Add "SwitchboardID", Argument.Value 时,它解决了断点问题并且新按钮有效,但现在报告菜单没有正确填写。
我可以单击 Return To Main 以返回到 Main Menu,Main Menu 上的所有其他按钮都可以正常工作,但新的 Reports Menu Button 除外。
这是总机背后的代码……
Option Compare Database
'------------------------------------------------------------
' Form_Current
'
'------------------------------------------------------------
Private Sub Form_Current()
On Error GoTo Form_Current_Err
'TempVars.Add "CurrentItemNumber", ItemNumber
TempVars.Add "CurrentItemNumber", ItemNumber.Value
Form_Current_Exit:
Exit Sub
Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit
End Sub
'------------------------------------------------------------
' Form_Open
'
'------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err
TempVars.Add "SwitchboardID", DLookup("SwitchboardID", "Switchboard Items", "[ItemNumber] = 0 AND [Argument] = 'Default'")
DoCmd.SetProperty "Label1", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.SetProperty "Label2", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.Requery ""
Form_Open_Exit:
Exit Sub
Form_Open_Err:
MsgBox Error$
Resume Form_Open_Exit
End Sub
'------------------------------------------------------------
' Option1_Click
'
'------------------------------------------------------------
Private Sub Option1_Click()
On Error GoTo Option1_Click_Err
On Error GoTo 0
If (Command = 1) Then
'TempVars.Add "SwitchboardID", Argument
TempVars.Add "SwitchboardID", Argument.Value
DoCmd.SetProperty "Label1", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.SetProperty "Label2", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.Requery ""
Exit Sub
End If
If (Command = 2) Then
DoCmd.OpenForm Argument, acNormal, "", "", acAdd, acNormal
Exit Sub
End If
If (Command = 3) Then
DoCmd.OpenForm Argument, acNormal, "", "", , acNormal
Exit Sub
End If
If (Command = 4) Then
DoCmd.OpenReport Argument, acViewReport, "", "", acNormal
Exit Sub
End If
If (Command = 5) Then
DoCmd.RunCommand acCmdSwitchboardManager
TempVars.Add "SwitchboardID", DLookup("SwitchboardID", "Switchboard Items", "[ItemNumber] = 0 AND [Argument] = 'Default'")
DoCmd.SetProperty "Label1", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.SetProperty "Label2", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.Requery ""
Exit Sub
End If
If (Command = 6) Then
DoCmd.CloseDatabase
Exit Sub
End If
If (Command = 7) Then
DoCmd.RunMacro Argument, , ""
Exit Sub
End If
If (Command = 8) Then
'Call Argument & "()"
Call Eval(Argument & "()")
Exit Sub
End If
Beep
MsgBox "Unknown option.", vbOKOnly, ""
Option1_Click_Exit:
Exit Sub
Option1_Click_Err:
MsgBox Error$
Resume Option1_Click_Exit
End Sub
'------------------------------------------------------------
' OptionLabel1_Click
'
'------------------------------------------------------------
Private Sub OptionLabel1_Click()
On Error GoTo OptionLabel1_Click_Err
On Error GoTo 0
If (Command = 1) Then
'TempVars.Add "SwitchboardID", Argument
TempVars.Add "SwitchboardID", Argument.Value
DoCmd.SetProperty "Label1", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.SetProperty "Label2", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.Requery ""
Exit Sub
End If
If (Command = 2) Then
DoCmd.OpenForm Argument, acNormal, "", "", acAdd, acNormal
Exit Sub
End If
If (Command = 3) Then
DoCmd.OpenForm Argument, acNormal, "", "", , acNormal
Exit Sub
End If
If (Command = 4) Then
DoCmd.OpenReport Argument, acViewReport, "", "", acNormal
Exit Sub
End If
If (Command = 5) Then
DoCmd.RunCommand acCmdSwitchboardManager
TempVars.Add "SwitchboardID", DLookup("SwitchboardID", "Switchboard Items", "[ItemNumber] = 0 AND [Argument] = 'Default'")
DoCmd.SetProperty "Label1", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.SetProperty "Label2", acPropertyCaption, DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
DoCmd.Requery ""
Exit Sub
End If
If (Command = 6) Then
DoCmd.CloseDatabase
Exit Sub
End If
If (Command = 7) Then
DoCmd.RunMacro Argument, , ""
Exit Sub
End If
If (Command = 8) Then
'Call Argument & "()"
Call Eval(Argument & "()")
Exit Sub
End If
Beep
MsgBox "Unknown option.", vbOKOnly, ""
OptionLabel1_Click_Exit:
Exit Sub
OptionLabel1_Click_Err:
MsgBox Error$
Resume OptionLabel1_Click_Exit
End Sub
任何建议将不胜感激..
提前致谢。
【问题讨论】:
-
那里的
Argument是什么?文本框? -
对不起,我不明白你的问题。这是一个总机,所以它们是命令按钮。这是你要问的吗?
-
你能在你的模块顶部添加一个
Option Explicit并重新编译 - -
Argument是什么 - 这是一个全球性的 -
我在最顶部添加了 Option Explicit 并编译,但单击新按钮时出现相同的错误。
标签: vba ms-access ms-access-2016