O
odeddror
Hi there,
I'm using Access 2010 and SQL Server 2008
I follow the Developer reference (chapter 1 and 2) and I created
An ODBC connection to my sql server
Then in access I have a binding form look like this
(I have one Customer link table in access)
Private Sub Form_Open(Cancel As Integer)
Dim cn As adodb.Connection
Dim rs As adodb.Recordset
'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection
'Create an instance of the ADO Recordset class,
'and set its properties
Set rs = New adodb.Recordset
With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM dbo_Customers"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub
Everything works fine
but I would like to create a module (myConnectionString) that hold the
connection string
And replace the odbc connection
something like that (chapter 2 - Dev reference)
'something like that
Public Sub GetData()
Dim sSQL As String
Dim oConnection1 As adodb.Connection
Dim m_sConnStr As String
m_sConnStr = "Provider='SQLOLEDB';Data Source='.';" & _
"Initial Catalog='Northwind';Integrated Security='SSPI';"
' Create and Open the Connection object.
Set oConnection1 = New adodb.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
With objConn
.Provider = "SQLOLEDB"
.DefaultDatabase = "Northwind"
.Properties("Data Source") = "MySqlServer"
.Properties("Integrated Security") = "SSPI"
.Open
End With
End Sub
my question is how to crerate a Connection string module (Function or Sub?)
and call (use) this from my form
Onload event?
Thanks,
Oded Dror
I'm using Access 2010 and SQL Server 2008
I follow the Developer reference (chapter 1 and 2) and I created
An ODBC connection to my sql server
Then in access I have a binding form look like this
(I have one Customer link table in access)
Private Sub Form_Open(Cancel As Integer)
Dim cn As adodb.Connection
Dim rs As adodb.Recordset
'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection
'Create an instance of the ADO Recordset class,
'and set its properties
Set rs = New adodb.Recordset
With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM dbo_Customers"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub
Everything works fine
but I would like to create a module (myConnectionString) that hold the
connection string
And replace the odbc connection
something like that (chapter 2 - Dev reference)
'something like that
Public Sub GetData()
Dim sSQL As String
Dim oConnection1 As adodb.Connection
Dim m_sConnStr As String
m_sConnStr = "Provider='SQLOLEDB';Data Source='.';" & _
"Initial Catalog='Northwind';Integrated Security='SSPI';"
' Create and Open the Connection object.
Set oConnection1 = New adodb.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
With objConn
.Provider = "SQLOLEDB"
.DefaultDatabase = "Northwind"
.Properties("Data Source") = "MySqlServer"
.Properties("Integrated Security") = "SSPI"
.Open
End With
End Sub
my question is how to crerate a Connection string module (Function or Sub?)
and call (use) this from my form
Onload event?
Thanks,
Oded Dror