|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub chaxun()
- Dim cnn As ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim mydata As String, mytable As String
- Dim SQL As String
- On Error GoTo 10
- mydata = ThisWorkbook.Path & "\1.mdb"
- mytable = "学生成绩"
- Set cnn = New ADODB.Connection
- With cnn
- .Provider = "microsoft.jet.oledb.4.0"
- .Open mydata
- End With
- SQL = "select * from " & mytable & " where 学生='" & UserForm1.TextBox1.Text & "'" '这里出问题了,要写全textbox1是哪的,因为你把这个代码是写在模块当中的
- Set rs = New ADODB.Recordset
- rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
- UserForm1.TextBox2 = rs(2)
- UserForm1.TextBox3 = rs(3)
- UserForm1.TextBox4 = rs(4)
- UserForm1.TextBox5 = rs(5)
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- 10 End Sub
复制代码 |
|