Computing.Net > Forums > Programming > VBA connection to SQLServer

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VBA connection to SQLServer

Reply to Message Icon

Original Message
Name: klaus
Date: August 20, 2002 at 01:26:43 Pacific
Subject: VBA connection to SQLServer
Comment:

Hi,
does anybody know how to connect directly to a SQLServer database to extract data for addresses in a word document?

i changed our database from MSAccess to a SQLServer database. The extension of the access database has tobe changed from mdb to adp.
While trying to connect directly to the access database as we did before there is no choice for adp extensions und Access driver.
If using the SQLServer driver the connection returns errors.

Beneath is the source code extract (a workaround connecing via ODBC system DSN) to connect to the SQLServer database.
If anybody can give me a hint how to setup a connection directly to SQLServer would be very helpful. Maybe i have to reference another library in VBA?

thanks
klaus
gDocAppObject.ActiveDocument.MailMerge.OpenDataSource Name:="", ConfirmConversions:= _
False, ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _

Connection:= _"DSN=HeGoSerienbrief;UID=dbo;APP=Microsoft® Query;WSID=NOTE02;DATABASE=HEGO;Network=DBMSLPCN;Trusted_Connection=Yes" _

, SQLStatement:= _
"SELECT KE_Seriendruck.Straße, KE_Seriendruck.Ort, KE_Seriendruck.Vorname, KE_Seriendruck.Nachname FROM HEGO" _
, SQLStatement1:=Chr(13) & Chr(10) & ".dbo.KE_Seriendruck KE_Seriendruck " & SerienWhere
With gDocAppObject.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
.Destination = wdSendToNewDocument
.Execute
End With


Report Offensive Message For Removal








Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software