我正在尝试在Access中创建一个表单,我将在其中搜索“搜索”功能以查找客户,然后我将在列表框中双击正确的匹配项以更新客户信息文本框。我成功完成了“当你键入时搜索”部分,但不是列表框双击更新表单部分。
我一直收到以下RunSQL错误:“RunSQL语句需要一个由SQL语句组成的参数”
问题是SQL语句在查询中运行得很好。
以下是代码:
Private Sub lstClient_DblClick(Cancel As Integer)
Dim selectedItem, strSQL, strSQL1 As String
Dim i As Integer
i = lstClient.ListIndex
selectedItem = lstClient.ItemData(i)
txtCustName.Value = selectedItem
strSQL = "SELECT tblClient.[Addresse] FROM tblClient WHERE tblClient.[Nom] ='" & selectedItem & "';"
strSQL1 = "SELECT tblClient.[Addresse] FROM tblClient WHERE tblClient.[Nom] ='Bernache Funeral home';"
DoCmd.RunSQL (strSQL1)
Text191.Value = strSQL1
End Sub
第二个语句(strSQL1)是我在查询中尝试过的,以确保它有效,并且确实有效。
提前致谢!
答案 0 :(得分:1)
尝试类似
的内容Dim db As Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL1)
Text191.Value = rs.Fields("Addresse").Value
Set rs = Nothing
Set db = Nothing