NigelShaw
Registered User.
- Local time
- Today, 23:46
- Joined
- Jan 11, 2008
- Messages
- 1,575
Hi everyone,
i have created a connection to an SQL database to add on and change data within the database structure as the specific program i use doesnt have the features i need. however, now the connection is created, im unsure on how to retrieve or update the tables. can anyone offer a bit of guidance please?
here is my connection-
many thanks guys
Nidge
i have created a connection to an SQL database to add on and change data within the database structure as the specific program i use doesnt have the features i need. however, now the connection is created, im unsure on how to retrieve or update the tables. can anyone offer a bit of guidance please?
here is my connection-
Code:
Public Sub SQLConnect()
On Error GoTo ErrorHandler
Dim Cnxn1 As ADODB.Connection
Dim strCnxn As String
Dim strServer As String
Dim strTrusted As String
Dim strApp As String
Dim strDatabase As String
Dim strNetwork As String
Dim strTable As String
strServer = forms!frmMain!txtServerName
strTrusted = forms!frmMain!txtTrust
strApp = forms!frmMain!txtApplication
strDatabase = forms!frmMain!txtDatabase
strNetwork = forms!frmMain!txtNetwork
strTable = "dbo.tblProductsAndServices"
' Open a connection using the Microsoft ODBC provided
Set Cnxn1 = New ADODB.Connection
Cnxn1.ConnectionString = "driver={SQL Server};" & _
"server={" & strServer & "};" & _
"Trusted_Connection={" & strTrusted & "};" & _
"APP={" & strApp & "};" & _
"DATABASE={" & strDatabase & "};" & _
"NETWORK={" & strDatabase & "};" & _
"TABLE={" & strTable & "};"
Cnxn1.Open strCnxn
Cnxn1.DefaultDatabase = strDatabase
' Display the provider to test
MsgBox "Cnxn1 provider: " & Cnxn1.Provider
'Now the connection is open, i need to get or alter the data here i think!!
' clean up
Cnxn1.Close
Set Cnxn1 = Nothing
Exit Sub
ErrorHandler:
If Not Cnxn1 Is Nothing Then
If Cnxn1.State = adStateOpen Then Cnxn1.Close
End If
Set Cnxn1 = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
many thanks guys
Nidge