Office中国论坛/Access中国论坛

标题: 2007下该代码老提示出错 [打印本页]

作者: pdsjm    时间: 2008-7-9 18:23
标题: 2007下该代码老提示出错
  1. Private Sub Fillbtns()
  2. '显示切换框中的列表
  3. '按钮数量
  4. Const conNumButtons As Integer = 8
  5. Dim rs As New ADODB.Recordset
  6. Dim strSQL As String
  7. Dim intbtn As Integer
  8. Me![btn1].SetFocus
  9. For intbtn = 2 To conNumButtons
  10. Me("btn" & intbtn).Visible = False
  11. Me("lbl" & intbtn).Visible = False
  12. Next intbtn
  13. '打开表Switchboard Items
  14. strSQL = "SELECT * FROM [Switchboard Items]"
  15. strSQL = strSQL & "WHERE [ItemNumber]>0 AND [SwitchboardID]=" & Me![SwitchboardID]
  16. strSQL = strSQL & "ORDER BY [ItemNumber]"
  17. Set rs = GetRs(strSQL)
  18. If (rs.EOF) Then
  19. Me![lbl1].Caption = "此切换面板页上无项目。"
  20. Else
  21. While Not ((rs.EOF))
  22. Me("btn" & rs![ItemNumber]).Visible = True
  23. Me("lbl" & rs![ItemNumber]).Visible = True
  24. Me("lbl" & rs![ItemNumber]).Caption = rs![ItemText]
  25. rs.MoveNext
  26. Wend
  27. End If
  28. '关闭数据集合和数据库
  29. rs.Close
  30. Set rs = Nothing
  31. End Sub
复制代码

[attach]30948[/attach]
[attach]30949[/attach]
[attach]30950[/attach]
作者: rcylbx    时间: 2008-7-9 20:03
if rs.eof then,应该不用括号.
操作符丢失的情况我也遇到过,非常可能是SQL语句中,应该留有空格的地方没有空格,可以仔细检查一遍是不是有的地方缺失空格.
以下代码谨供参考:
strStemp = "select * from tblDanWeiJiaoFeiCeSuanGuoDu  where 上报状态='未上报' ORDER BY [单位上报编号] DESC"
         
rs.Open strStemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

[ 本帖最后由 rcylbx 于 2008-7-9 20:15 编辑 ]
作者: pdsjm    时间: 2008-7-18 17:23
[:50] 多谢了,我再检查一遍




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3