Office中国论坛/Access中国论坛

标题: [求助]在VBA中使用SQL语句时出错 [打印本页]

作者: 好学    时间: 2006-8-20 01:31
标题: [求助]在VBA中使用SQL语句时出错
Private Sub Form_Load()
    Dim strSQL As String
    strSQL ="Select 数值, DCount([数值],"码表","数值<" & [数值])+1 AS 排名 from 码表" _
    & ORDER BY DCount([数值],"码表","数值<" & [数值])+1;
    Me!要求结果_子窗体.Form.RecordSource = strSQL
End Sub


上面的提示出错:缺少语句结束!             请问我错在那里呢?
作者: fan0217    时间: 2006-8-20 02:05
strSQL ="Select 数值, DCount([数值],"码表","数值<" & [数值])+1 AS 排名 from 码表" _
    & ORDER BY DCount([数值],"码表","数值<" & [数值])+1;

这句明显的有错误,变量和函数不能用双引号引起来。以下语句没有进行测试,仅是根据书写格式进行了修改。如不能通过测试,请自己再做必要的修改。


strSQL ="Select 数值," & DCount([数值],"码表","数值<" & [数值])+1 & " AS 排名 from 码表 ORDER BY " & DCount([数值],"码表","数值<" & [数值])+1;"


作者: 好学    时间: 2006-8-20 03:36
还是不行啊[em01][em01][em01]



[attach]19873[/attach]

作者: andymark    时间: 2006-8-20 04:12
建议把SQL写到窗体的记录源上去

[attach]19874[/attach]

作者: 好学    时间: 2006-8-20 06:45
andymark版主我是参考查询写的,如果用查询是没问题的,但我有特殊的原因才用VBA写.




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