Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

access主切换面板提示执行命令时错误

郑杰  发表于:2013-12-16 12:20:59  
复制

Option Compare Database

Private Function HandleButtonClick(intbtn As Integer)
' 处理按钮click事件
    Const conCmdGotoSwitchboard = 1
    Const conCmdNewForm = 2
    Const conCmdOpenReport = 3
    Const conCmdExitApplication = 4
    Const conCmdRunMacro = 8
    Const conCmdRunCode = 9
    Const conCmdOpenPage = 10
    Const conErrDoCmdCancelled = 2501
    Dim rs As ADODB.Recordset
    Dim strSQL As String
    On Error GoTo HandleButtonClick_Err
  Set rs = CreateObject("ADODB.Recordset")
  strSQL = "SELECT * FROM [Switchboard Items]"
  strSQL = strSQL & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intbtn
  Set rs = GetRs(strSQL)
    If (rs.EOF) Then
 MsgBox "读取 Switchboard Items 表时出错。"
    rs.Close
    Set rs = Nothing
    Exit Function
  End If
Select Case rs![Command] ' 进入另一个切换面板
    Case conCmdGotoSwitchboard
    Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
    ' 打 开一个新窗体
    Case conCmdNewForm
    DoCmd.OpenForm rs![Argument]
    ' 打开报表
    Case conCmdOpenReport
    DoCmd.OpenReport rs![Argument], acPreview
    ' 退出应用程序
    Case conCmdExitApplication
    CloseCurrentDatabase
    ' 运行宏.
    Case conCmdRunMacro
    DoCmd.RunMacro rs![Argument]
    ' 运行代码.
    Case conCmdRunCode
    Application.Run rs![Argument]
   ' 打开一个数据存取页面
    Case conCmdOpenPage
DoCmd.OpenDataAccessPage rs![Argument]
    ' 未定义的选项
    Case Else
    MsgBox "未知选项"
    End Select
   ' Close the recordset and the database.
    rs.Close
HandleButtonClick_Exit:
    On Error Resume Next
    Set rs = Nothing
    Exit Function
HandleButtonClick_Err:
    If (Err = conErrDoCmdCancelled) Then
        Resume Next
    Else
        MsgBox "执行命令时出错。", vbCritical
        Resume HandleButtonClick_Exit
    End If
End Function

 

Top
123木头人 发表于:2013-12-16 14:20:47

把这一句注释掉:On Error GoTo HandleButtonClick_Err,就是在这一句前面回一个英文引号。

加了以扣你会看到更具体的错误,知道具体要求的错误才好解决。



郑杰 发表于:2013-12-16 20:46:41

我把那个删了以后提示我那几个错误的窗体拼写错误或者引用了不存在的窗体。可能是宏那有问题。我没检查出来



总记录:2篇  页次:1/1 9 1 :