vb6.0 Excel数据导入Access不能任意路径,必须要EXCEL文件和ACCESS数据库在同一个目录下才能成功导入,请大神帮忙看看怎么修改一下才能EXCEL在任意位置都可以导入。
----------------------------打开数据库找到数据表部分------------------
Private Sub Form_Load()
Dim cnn1 As New ADODB.Connection
Dim rstSchema As New ADODB.Recordset
Command1.Enabled = False
Command2.Enabled = False
dataBaseName = "data.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & App.Path & "\data.mdb"
cnn1.Open strCnn
Set rstSchema = cnn1.OpenSchema(adSchemaTables)
If (Not rstSchema.EOF) Then
If rstSchema!TABLE_TYPE = "TABLE" Then
sjbm = rstSchema!TABLE_NAME
End If
End If
rstSchema.Close
cnn1.Close
Set rstSchema = Nothing
Set cnn1 = Nothing
End Sub
----------------------------打开数据库找到数据表部分------------------
---------------导入部分-------------
Private Sub Command2_Click()
If Text1.Text = "" Then
MsgBox "亲,请加载正确的Excel文件!", vbCritical, "文件未找到"
Exit Sub
End If
On Error GoTo ErrorHandler ' 打开错误处理程序
sql = "insert INTO " & sjbm & " IN '" & dataBaseName & "' select * from [data$]"
Conn.Execute (sql)
MsgBox "数据导入成功~~~╰( ̄▽ ̄)╮", vbInformation, "信息提示"
Command1.Enabled = False
Command2.Enabled = False
Exit Sub
ErrorHandler: ' 错误处理程序
MsgBox Err.Description
End Sub
导入不同文件夹的EXCEL文件会提示找不到数据库文件,我就没懂怎么回事,不知道是那里的地址错了。
只有EXCEL和数据库在同文件夹才能导入成功。请教~~~~~