Office中国论坛/Access中国论坛

标题: 有偿求代码,如何在VBA中自动增加ODBC项? [打印本页]

作者: cnwang    时间: 2003-1-2 18:37
标题: 有偿求代码,如何在VBA中自动增加ODBC项?
联系:0756-6655634
作者: zhengjialon    时间: 2003-1-2 20:39
没仔细看过,可能有帮助:
http://www.office-cn.net/bbs/dispbbs.asp?boardID=2&RootID=17967&ID=17967


[此贴子已经被zhengjialon于2003-1-2 12:38:41编辑过]


作者: cnwang    时间: 2003-1-3 00:54
google帮我忙,搞掂:

Private Const ODBC_ADD_SYS_DSN = 4
Private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As Long

Public Function newodbc(StrDriver, StrAttributes As String) As Boolean
    LoadDbSource2 = SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, StrDriver, StrAttributes)
End Function

Public Sub newodbc1()
    Dim StrAttributes As String
    StrAttributes = "DSN=newODBC" & Chr(0) & "Desciption=newodbc" & Chr(0)
    StrAttributes = StrAttributes & "Dbq=" & CurrentProject.Path & "\colorset.mdb" & Chr(0) & "FIL=MS Access;" & Chr(0)
    StrAttributes = StrAttributes & "MaxBufferSize=2048" & Chr(0) & "ageTimeout=5" & Chr(0)

    newodbc "Microsoft Access Driver (*.mdb)", StrAttributes
    msgbox "cnwang,又省了一笔银子。。。"
End Sub

作者: jhzlzc29    时间: 2003-1-3 02:00
可否解释一下?
我实在看不明白




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3