|
Public Sub drde()
Dim myData As String, myTable As String, SQL As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Integer
Application.ScreenUpdating = False
Sheet13.Select
ActiveSheet.Cells.Clear
On Error GoTo 11
myData = "c:\fjdx\declk.mdb"
myTable = "定额"
Set cnn = New ADODB.Connection
cnn.Provider = "microsoft.jet.oledb.4.0"
cnn.Open , myData, , psw = 123
SQL = "select * from " & myTable & " order by 顺号"
Set rs = cnn.Execute(SQL)
If rs.EOF And rs.BOF Then
MsgBox "数据表没有记录!", vbCritical
Else
For i = 1 To rs.Fields.Count
Cells(1, i) = rs.Fields(i - 1).Name
Next i
With Range(Cells(1, 1), Cells(1, rs.Fields.Count))
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
Range("A5").CopyFromRecordset rs
ActiveSheet.Cells.Font.Size = 10
ActiveSheet.Columns.AutoFit
End If
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
想用它打开密码为123的数据库,为啥不行,错在那里?请高手指点! |
|