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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA connection to SQLServer

Reply to Message Icon

Name: klaus
Date: August 20, 2002 at 01:26:43 Pacific
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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: VBA connection to SQLServer

VBA- connect to web with user/pass www.computing.net/answers/programming/vba-connect-to-web-with-userpass/6418.html

Connecting to a MS-SQL Database www.computing.net/answers/programming/connecting-to-a-mssql-database/9681.html

Connect to file on web w/ VBA www.computing.net/answers/programming/connect-to-file-on-web-w-vba/6465.html