Access Adp 项目连接SQL 函数,
使用方法:
1.新建Access Adp项目
2.在模块中新建一个模块,粘贴以下代码
3.新建一个登录窗体,调用即可
Public Function saConnect(ByVal strServer As String, ByVal strDatabase As String, _
ByVal strUsername As String, ByVal strPassword As String) As Boolean
On Error GoTo err
Connect:
Dim strCn As String
strCn = "PROVIDER=SQLOLEDB.1;"
'strCn = strCn & "Workstation Id = HY"
strCn = strCn & "DATA SOURCE=" & strServer & ";"
strCn = strCn & "INITIAL CATALOG=" & strDatabase & ";"
strCn = strCn & "USER ID=sa;"
strCn = strCn & "PASSWORD=;"
strCn = strCn & "PERSIST SECURITY INFO=TRUE;"
strCn = strCn & "Use Procedure for Prepare=1;"
strCn = strCn & "Auto Translate=True;"
strCn = strCn & "Packet Size=4096;"
'Debug.Print strCn
CurrentProject.OpenConnection strCn
theConnect = True
Exit Function
err:
MsgBox "错误代码: " & err.Number & vbCrLf & vbCrLf & _
"错误描述: " & err.Description, vbCritical + vbOKOnly, theTitle
End Function
实例补充
http://down.qiannao.com/space/file/wangjerry/share/2011/8/19/Jerrysoft.rar/.page