作者yougetit1999 (清)
看板Visual_Basic
标题[VBA ] excel中对access查询的问题?
时间Fri Apr 21 16:59:43 2006
我在EXCEL中用VBA写了一段查询ACCESS资料库的程式
原始档请由此下载 ftp://203.70.60.138/test.rar
请问我的语法哪里有错吗,否则都查不到资料,谢谢
Private Sub CommandButton1_Click()
On Error GoTo 100
If TextBox1.Text = "" Then
MsgBox "请输号码", 1 + 16, "系统提示"
TextBox1.SetFocus
Else
Dim DB1 As Database
Dim RS1 As Recordset
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\资料.mdb")
Set RS1 = Database.OpenRecordset(Name:="成绩表", Type:=dbOpenDynaset)
RS1.FindFirst "名字='" & TextBox1.Value & "'"
If RS1.NoMatch = True Then
MsgBox "对不起,没有该记录"
RS1.Close
Exit Sub
Else
TextBox2.Value = RS1.Fields("号码").Value
TextBox3.Value = RS1.Fields("成绩").Value
TextBox4.Value = RS1.Fields("名字").Value
End If
RS1.Close
Set RS1 = Nothing
Set DB1 = Nothing
End If
Exit Sub
100:
MsgBox "找不到符合条件的记录", 1 + 16, "系统提示"
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.70.60.138