sql = "select * from cust where 客户编号='focustext1.text'" 改成: sql = "select * from cust where 客户编号='" & focustext1.text & "'"
sorry 是 sql = "select * from cust where 客户编号=“ & val(focustext1.text)
你的错误在于这句话:sql = "select * from cust where 客户编号='focustext1.text'" 你的表中肯定没有客户编号等于focustext1.text的记录,所以得到的记录集为空,rs1.Fields("客户编号") = Val(FocusText1.Text)这句话当然会报错。你可以增加判断if not rs1.eof then,保证记录集不为空,另外关于sql语句的错误,前面的仁兄已提出了修改意见。 另外:我觉得你使用ado对象的方法好像有些怪异,一般很少见到你这种写法,而且在我的印象中,Set rs1 = New Recordset这句应为 Set rs1 = New adodb.Recordset,不知你这种写法行不行。
sql = "select * from cust where 客户编号='" & focustext1.text & "'"
sql = "select * from cust where 客户编号=“ & val(focustext1.text)
你的表中肯定没有客户编号等于focustext1.text的记录,所以得到的记录集为空,rs1.Fields("客户编号") = Val(FocusText1.Text)这句话当然会报错。你可以增加判断if not rs1.eof then,保证记录集不为空,另外关于sql语句的错误,前面的仁兄已提出了修改意见。
另外:我觉得你使用ado对象的方法好像有些怪异,一般很少见到你这种写法,而且在我的印象中,Set rs1 = New Recordset这句应为 Set rs1 = New adodb.Recordset,不知你这种写法行不行。