此代码用于填充表单中的文本框,其中sql查询代表hr_id从表RR_info获取数据。它将rr_info的hr_id与listbox的有界值进行比较。
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
答案 0 :(得分:2)
你不需要字符串“DoCmd.RunSQL SQL”。 并且最好使用.Value insted of .Text