在运行时错误3129中需要帮助,并使用SELECT语句

发布于 2025-02-11 15:17:36 字数 849 浏览 0 评论 0原文

代码在下面。在第一和最后一行中遇到错误。我认为第二行上有一个额外的> )),但这不会解释最后一行的错误。

DoCmd.RunSQL (sqlStr)

strSQL = "SELECT fct_monitoring.MeasureID FROM fct_monitoring WHERE MeasureID IN (" & _
    Chr(34) & "CAUTI_Rate_All" & Chr(34) & "," & _
    Chr(34) & "CDI_LabID" & Chr(34) & "," & _
    Chr(34) & "CLABSI_Rate_All" & Chr(34) & "," & _
    Chr(34) & "Falls_Injury" & Chr(34) & "," & _
    Chr(34) & "READ-1" & Chr(34) & ")" & _
    Chr(34) & "CAUTI_SIR_All" & Chr(34) & "," & _
    Chr(34) & "CDI_SIR" & Chr(34) & "," & _
    Chr(34) & "CLABSI_SIR_All" & Chr(34) & "," & _
    " GROUP BY fct_monitoring.MeasureID;"

Set msrRst = dbs.OpenRecordset(strSQL)

Code is below. Getting errors on first and last lines. I think there is an extra ( or else missing ) on 2nd line but that wouldn't explain the error on the last line.

DoCmd.RunSQL (sqlStr)

strSQL = "SELECT fct_monitoring.MeasureID FROM fct_monitoring WHERE MeasureID IN (" & _
    Chr(34) & "CAUTI_Rate_All" & Chr(34) & "," & _
    Chr(34) & "CDI_LabID" & Chr(34) & "," & _
    Chr(34) & "CLABSI_Rate_All" & Chr(34) & "," & _
    Chr(34) & "Falls_Injury" & Chr(34) & "," & _
    Chr(34) & "READ-1" & Chr(34) & ")" & _
    Chr(34) & "CAUTI_SIR_All" & Chr(34) & "," & _
    Chr(34) & "CDI_SIR" & Chr(34) & "," & _
    Chr(34) & "CLABSI_SIR_All" & Chr(34) & "," & _
    " GROUP BY fct_monitoring.MeasureID;"

Set msrRst = dbs.OpenRecordset(strSQL)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装纯掩盖桑 2025-02-18 15:17:36

您真的只想打印出SQL语句 - 试图解决所有这些串联是错误的错误。

strSQL = "SELECT fct_monitoring.MeasureID FROM fct_monitoring WHERE MeasureID IN (" & _ 
    Chr(34) & "CAUTI_Rate_All" & Chr(34) & "," & _ 
    Chr(34) & "CDI_LabID" & Chr(34) & "," & _ 
    Chr(34) & "CLABSI_Rate_All" & Chr(34) & "," & _ 
    Chr(34) & "Falls_Injury" & Chr(34) & "," & _ 
    Chr(34) & "READ-1" & Chr(34) & ")" & _ 
    Chr(34) & "CAUTI_SIR_All" & Chr(34) & "," & _ 
    Chr(34) & "CDI_SIR" & Chr(34) & "," & _ 
    Chr(34) & "CLABSI_SIR_All" & Chr(34) & "," & _ 
    " GROUP BY fct_monitoring.MeasureID;"

Debug.Print(sqlStr)

SQL语句,您可以更好地阅读 - 如果需要

通过该调试输出,您可以查看一些使某些更有意义的东西(应该是 这种更好的格式,我想我可以看到,大概是在阅读1之后,您有一个括号,应该是引用,而在clabsi_sir_all之后,您有一个逗号,您应该有一个括号(看起来像是有人决定移动一条线)) 。

You really want to just print out the sql statement - it is too error prone to try to work out all these concatenations.

strSQL = "SELECT fct_monitoring.MeasureID FROM fct_monitoring WHERE MeasureID IN (" & _ 
    Chr(34) & "CAUTI_Rate_All" & Chr(34) & "," & _ 
    Chr(34) & "CDI_LabID" & Chr(34) & "," & _ 
    Chr(34) & "CLABSI_Rate_All" & Chr(34) & "," & _ 
    Chr(34) & "Falls_Injury" & Chr(34) & "," & _ 
    Chr(34) & "READ-1" & Chr(34) & ")" & _ 
    Chr(34) & "CAUTI_SIR_All" & Chr(34) & "," & _ 
    Chr(34) & "CDI_SIR" & Chr(34) & "," & _ 
    Chr(34) & "CLABSI_SIR_All" & Chr(34) & "," & _ 
    " GROUP BY fct_monitoring.MeasureID;"

Debug.Print(sqlStr)

With that debug output you can look at something that makes a bit more sense (it should be a sql statement you can read better - if you want, you can even paste it into a query in sql design view and run it.

Although actually in this better format, I think I can see that probably after READ-1 you have a parenthesis that should be a quote, and after CLABSI_SIR_All you have a comma where you should have a parenthesis (this looks like someone decided to move a line around).

马蹄踏│碎落叶 2025-02-18 15:17:36

从发布的代码准确地确定您想做什么,但这应该是接近的:

strSQL = "SELECT distinct fct_monitoring.MeasureID " & _
         "   FROM fct_monitoring WHERE MeasureID IN " & _
         "('CAUTI_Rate_All','CDI_LabID','CLABSI_Rate_All','Falls_Injury', " & _
         " 'READ-1','CAUTI_SIR_All','CDI_SIR','CLABSI_SIR_All')"

不需要所有这些chr(34),因为您可以使用单价。

Not possible to be sure from your posted code exactly what you want to do, but this should maybe be close:

strSQL = "SELECT distinct fct_monitoring.MeasureID " & _
         "   FROM fct_monitoring WHERE MeasureID IN " & _
         "('CAUTI_Rate_All','CDI_LabID','CLABSI_Rate_All','Falls_Injury', " & _
         " 'READ-1','CAUTI_SIR_All','CDI_SIR','CLABSI_SIR_All')"

No need for all that Chr(34) since you can use single-quotes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文