|
这是andymark版主写的,请问如果数据库有密码,该如何?还有我打开窗体1为什么不行?
Dim strPath As String
Dim strAccDir As String
Dim strAccPath As String
Dim strDbPath As String
Dim StrWrkgrpPath As String
Dim StrCnn As String
Dim Conn As New ADODB.Connection
strAccDir = SysCmd(acSysCmdAccessDir)
strAccPath = strAccDir & "MSACCESS.EXE"
strDbPath = CurrentProject.Path & "\data\db1.mdb"
StrWrkgrpPath = CurrentProject.Path & "\data\Security.mdw"
'测试帐号密码是否正确,以防弹出系统的登陆窗口
StrCnn = "data source= " & strDbPath & ";"
StrCnn = StrCnn & "jet oledb:system database= " & StrWrkgrpPath & ";"
StrCnn = StrCnn & "user id= abcdassword=12345"
With Conn
.Provider = "Microsoft.Jet.oledb.4.0"
.ConnectionString = StrCnn
.Open
End With
'用现有的帐号密码打开数据库
strPath = Chr(34) & strAccPath & Chr(34) & " " _
& Chr(34) & strDbPath & Chr(34) & " " _
& "/wrkgrp " & Chr(34) & StrWrkgrpPath & Chr(34) & " " _
& "/User " & Chr(34) & "abcd" & Chr(34) & " " _
& "/Pwd " & Chr(34) & "12345" & Chr(34)
Shell strPath, vbMaximizedFocus
DoCmd.OpenForm "窗体1" |
|