【问题标题】:how can i fix following VBA code我如何修复以下 VBA 代码
【发布时间】:2013-09-22 10:46:06
【问题描述】:

此代码用于填充文本框,其中 sql 查询代表 hr_id 从表 RR_info 中获取数据。它将 rr_info 的 hr_id 与列表框的有界值进行比较。

 Private Sub Form_Load()
 Dim SQL As String
 Dim db As Database
 Dim rs As DAO.Recordset

 SQL = "select * from RR_info where hr_id = " & Forms![hhrrr]![List38] & ";"
 Set db = CurrentDb
 Set rs = db.OpenRecordset(SQL)
                                'DoCmd.RunSQL SQL 'at this point it gives me error 2342
 Me.RR_ID.value = rs!RR_ID
 Me.HR_ID.value = rs!HR_ID 
 Me.Room_No.value = rs![Room No] 
 Me.No_of_Beds.value = rs!No_of_Beds
 Me.Room_Category.value = rs!Room_Category

 Set rs = Nothing
 Set db = Nothing
 End Sub

【问题讨论】:

    标签: ms-access ms-access-2007 vba ms-access-2010 ms-access-2003


    【解决方案1】:

    您不需要字符串“DoCmd.RunSQL SQL”。 最好使用 .Text 的 .Value 插入

    【讨论】:

    • 通过应用您的建议,问题并未解决,但出现错误,错误代码为 2448 和“您无法为该对象分配值”。
    • 运行时错误 3075。语法错误在查询表达式“hr_id=”中缺少运算符。
    • 还有一件事我已经从属性窗口中删除了行源属性,现在上面的 VBA 代码正在做所有事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 2019-01-20
    相关资源
    最近更新 更多