Private Sub Form_Load()
Dim cnn As New ADODB.Connection
If Dir(App.Path + "\123.mdb") <> "" Then
cnn.ConnectionString = "provider=microsoft.jet.oledb.4.0;" + "data source=" + App.Path + "\123.mdb;"
cnn.Open
If cnn.State = adStateOpen Then
MsgBox "打開資料庫"
End If
cnn.Close
If cnn.State = adStateClosed Then
MsgBox "關閉資料庫"
End If
Else
MsgBox ("找不到人事資料庫")
End If
End Sub
輸出的結果為什么是找不到人事資料庫
uj5u.com熱心網友回復:
第三句改為 If Dir(" & App.Path & "\123.mdb)<>" "then 試試uj5u.com熱心網友回復:
代碼要做縮進Private Sub Form_Load()
Dim cnn As New ADODB.Connection
If Dir(App.Path + "\123.mdb") <> "" Then
cnn.ConnectionString = "provider=microsoft.jet.oledb.4.0;" + "data source=" + App.Path + "\123.mdb;"
cnn.Open
If cnn.state = adStateOpen Then
MsgBox "打開資料庫"
End If
cnn.Close
If cnn.state = adStateClosed Then
MsgBox "關閉資料庫"
End If
Else
MsgBox ("找不到人事資料庫")
MsgBox App.Path + "\123.mdb" '檢查下這個檔案路徑'
End If
End Sub
原因很明顯,檔案不存在啊。
uj5u.com熱心網友回復:
dir陳述句未找到檔案,可以在之前加debug.print dir(app.path & "\123.mdb") 看看值是不是檔案名123.mdb,否則檢查檔案是否存在。uj5u.com熱心網友回復:
檔案放的位置,一定要是現在程式運行的位置,就是跟你工程1.vbp檔案同在一個檔案夾轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/86790.html
上一篇:axWindowsMediaPlayer時間顯示不正常
下一篇:EXCEL資料庫
