补充:一下是VBA,来自网上,以前用的很好,最近出现问题,在另一台电脑上正常。
On Error GoTo Err_GetConnect
Dim strConnect As String '连接字串
Dim cnn As Object 'ADODB.Connection
Dim strDB As String
strDB = Me.txtDatabase
If strDB Like ".\*" Then strDB = CurrentProject.Path & Mid(strDB, 2)
Me.lblTip.Caption = conMsgConnecting
Me.Repaint
MsgBox "1"
'使用Access数据库时
Select Case Me.grpDatabaseType
Case Me.optDBTypeAccess.OptionValue
MsgBox "12"
'先用ADO通过OLEDB直接连接数据库进行测试
'strConnect = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & strDB & _
";Jet OLEDB:Database Password=" & Nz(Me.txtPassword)
strConnect = "Provider=Microsoft.ACE.OLEDB.12.0" & _
";Data Source=" & strDB & _
";Jet OLEDB:Database Password=" & Nz(Me.txtPassword)
MsgBox "121"
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = strConnect
' cnn.CommandTimeout = 180
MsgBox "1211"
cnn.Open ‘问题出在这里’
MsgBox "12111"
cnn.close
MsgBox "1212"
'未出错说明设置正确,返回链接表需要的连接字串
GetConnect = "MS Access" & _
";DATABASE=" & strDB & _
";UID=" & Me.txtUserName
MsgBox "122"
If Nz(Me.txtPassword) <> "" Then GetConnect = GetConnect & ";PWD=" & Me.txtPassword
'使用SQL Server数据库时