|
自动创建ODBC
- Function gt_TestOdbc(rstDsn As String, rstrUser As String, rstrPassword As String, rstrTableName As String) As Boolean
- On Error GoTo err_c
- DoCmd.SetWarnings False
- Dim Response As Integer
- Dim connstr As String, mydb As DAO.Database
- connstr = "ODBC;DSN=" & rstDsn & ";"
- connstr = connstr & "UID=" & rstrUser & ";"
- connstr = connstr & "PWD=" & rstrPassword & ";"
- Dim dbs As DAO.Database
- Dim qdf As DAO.QueryDef
- '
- ' Set dbs = CurrentDb()
- ' Set qdf = dbs.CreateQueryDef("")
- '
- ' 'Replace <DSN> with the actual DSN that points to your SQL Server.
- ' qdf.connect = connstr ' "ODBC;DSN=<DSN>;UID=" & strUserId & "WD=" & _
- ' strPassword & ";DATABASE=pubs"
- ' qdf.ReturnsRecords = False
- '
- ' 'Any SQL statement will work below.
- ' qdf.SQL = "SELECT * FROM " & rstrTableName
- ' qdf.Execute
- '
- '
- Set mydb = DBEngine.Workspaces(0).OpenDatabase("", False, False, connstr)
- ' curpos = 0
- gt_TestOdbc = True
- Exit Function
- err_c:
- gt_TestOdbc = False
- ' MsgBox "数据库用户,口令错误,重新登录!", , "文具"
- ' DoCmd.RunSQL "delete from tblOdbcCfg"
- ' DoCmd.Quit
- Exit Function
- End Function
复制代码
|
|