Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Sql Problem
I want to loop through a table (tblrelmanager) and merge the results with a

> word doc. The trouble is I am not used to SQL coding and I cant get my
> WHERE

> statement to work.

> Can anyone tell me where I am going wrong

>

> Thanks in advance

> Dave

>

>

>

>

>

> Set rst = db.OpenRecordset("tblrelmanager")

>

> Do Until rst.EOF

>

> Set objWord = GetObject("N:\Customer Management  Centre\Warrington\Re
ach

> Team\Database\fire risk assessment.doc", "Word.Document")

> objWord.Application.Visible = True

> objWord.MailMerge.OpenDataSource _

> Name:="D:\Documents and Settings\All  Users\Documents\WSS\
WSS.mdb", _

> LinkToSource:=True, _

> Connection:="table tblAccenture", _

> SQLStatement:="SELECT * FROM [tblAccenture] WHERE [Relationship

> Manager] = rst.[Relationship Manager]"

>

> objWord.MailMerge.Execute

> rst.MoveNext

> Loop



Report this thread to moderator Post Follow-up to this message
Old Post
David
07-23-05 01:23 AM


Re: Sql Problem
David (david.roebuck@btinternet.com)  writes:
> I want to loop through a table (tblrelmanager) and merge the results
> with a word doc. The trouble is I am not used to SQL coding and I cant
> get my WHERE statement to work.
>
> Can anyone tell me where I am going wrong
>
> Set rst = db.OpenRecordset("tblrelmanager")
> Do Until rst.EOF
>    Set objWord = GetObject("N:\Customer Management
>     Centre\Warrington\Re
ach
>                  Team\Database\fire risk assessment.doc",
>                  "Word.Document")
>    objWord.Application.Visible = True
>    objWord.MailMerge.OpenDataSource _
>        Name:="D:\Documents and Settings\All
>         Users\Documents\WSS\
WSS.mdb", _
>       LinkToSource:=True, _
>       Connection:="table tblAccenture", _
>       SQLStatement:="SELECT * FROM [tblAccenture] " & _
>         WHERE [Relationship Manager] = rst.[Relationship Manager]"
>    objWord.MailMerge.Execute
>    rst.MoveNext
> Loop

This a newsgroup for MS SQL Server, and I don't know anything about
mail merge. I didn't even know that you used SQL for it.

But I would expect this to be better:

SQLStatement:="SELECT * FROM [tblAccenture] " & _
WHERE [Relationship Manager] = '" & _
rst("Relationship Manager") & "'"

That is, you need to expand the field value before you pass it to
mail merge. And rst is just another VB(A) obejct, and you refer to its
elements and indexes as any other VB(A) object.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
07-23-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 11:12 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006