View Single Post
  #1  
Old April 18th 07, 06:34 PM posted to microsoft.public.outlook.program_vba
RosH
external usenet poster
 
Posts: 4
Default SQL server integration with Outlook VBA

Dear All,

I have been trying to integrate Outlook with an SQL database, even
though I am a newbie to SQL server databases. The following is the
procedure code that I used for inserting a new row into a table called
Accounts. The code is working fine, but a hunch from the back of my
head tells me the code is not efficient and not according to the best
practices because I rely on creation of a string to do the database
operations. I would like to represent it to the outlook experts here
who can guide me to learn the best way to connect, insert or update a
database from Outlook VBA. Thanks in advance

-------------------------CODE---------------------------

Public Sub SQLInsertNewAccount(ByVal objAccount As Accounts)

' Declarations
Dim Dbcon As New ADODB.Connection
Dim Dbcom As New ADODB.Command

' Initialisations
Dbcon.ConnectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Initial Catalog=CRM;Data
Source=SERVER\SQLEXPRESS"
Dbcon.Open

' Command Object
Dbcom.CommandText = "INSERT INTO Accounts(RemoteID, OutlookID,
SyncStatus, Name, Address, City, PostalCode, Country, Phone, Fax,
WebPage, Description, Industry, EmployeeCount) VALUES ('" _
& objAccount.RemoteID & "', '" _
& objAccount.OutlookID & "', '" _
& objAccount.SyncStatus & "', '" _
& objAccount.Name & "', '" _
& objAccount.Address & "', '" _
& objAccount.City & "', '" _
& objAccount.PostalCode & "', '" _
& objAccount.Country & "', '" _
& objAccount.Phone & "', '" _
& objAccount.Fax & "', '" _
& objAccount.WebPage & "', '" _
& objAccount.Description & "', '" _
& objAccount.Industry & "', '" _
& objAccount.EmployeeCount & "')"


' Execution
Dbcom.ActiveConnection = Dbcon
Dbcom.Execute

' The End
Dbcon.Close
Set Dbcon = Nothing
Set Dbcom = Nothing

End Sub

Ads