isyanye
isyanye
采纳率0%
2019-12-16 22:26

excel vba中调用SQLConfigDataSource函数时返回值总是FALSE,是哪里出错了?请高手指教!

5

excel vba中调用SQLConfigDataSource函数时返回值总是FALSE,是哪里出错了?请高手指教!
代码如下:
Private Const ODBC_ADD_SYS_DSN = 4
Private Declare PtrSafe 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 LoadDbSource2(StrDriver, StrAttributes As String) As Boolean
LoadDbSource2 = SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, StrDriver, StrAttributes)
End Function

Sub hong()

Dim StrAttributes As String
StrAttributes = "DSN=AccessODBC2" & Chr(0) & "Desciption=动态加载ODBC示例" & Chr(0)
StrAttributes = StrAttributes & "Dbq=" & "C:\Users\Administrator\Desktop\180608YearInterestRate.mdb" & Chr(0) & "FIL=MS Access;" & Chr(0)
StrAttributes = StrAttributes & "MaxBufferSize=2048" & Chr(0) & "PageTimeout=5" & Chr(0) & Chr(0)
Call LoadDbSource2("Microsoft Access Driver (*.mdb)", StrAttributes)

End Sub

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

相关推荐