473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

database record to Word template?

The code below works fine from Access, but from SQL Server (commented string), only the last of the bookmarks in the Word template has the field data filled in (strange). Any ideas? A driver issue?

Expand|Select|Wrap|Line Numbers
  1. Sub PrintForm(showOnly,uid)
  2.     On Error Resume Next
  3.     Dim wdApp,mDoc,SQLstr,cnStr,rs,db
  4.     Set wdApp = CreateObject("Word.Application")
  5.     Set db=CreateObject("ADODB.Connection")
  6.     wdApp.Visible=true
  7.     cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databasePath & ";User ID=admin;Password=;"
  8.     'cnStr = "Provider=SQLOLEDB;Data Source=" & databasePath & ";Database=databasename;UID=user;PWD=pw;"
  9.     SQLstr = "SELECT * FROM [" & tableName & "] WHERE [ID]=" & uid & ";"
  10.     Set mDoc = wdApp.Documents.Add("\\server\forms\template2.dot")
  11.     db.Open cnStr
  12.     Set rs=db.Execute(SQLstr,,1)    
  13.  
  14.     For i = 0 to rs.Fields.Count-1
  15.         If mDoc.Bookmarks.Exists(rs(i).name) then mDoc.Bookmarks(rs(i).name).Range.Text="" & rs(i).value
  16.     Next
  17.  
  18.     rs.Close
  19.     Set rs=Nothing
  20.     db.Close
  21.     Set db=Nothing
  22.     Select Case showOnly
  23.         Case True
  24.             wdApp.Visible = True
  25.         Case False
  26.             mDoc.PrintOut False
  27.             wdApp.Quit 0
  28.             Set mDoc = Nothing
  29.             Set wdApp = Nothing
  30.     End Select
  31.  
  32. End Sub
  33.  
Thanks for your help.
Oct 17 '06 #1
0 1174

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
1
by: Franck | last post by:
Does anyone know how I can export my data from a database and put it into a predefined Word template document. I'm using C#.NET and have datasets with all the data I need. I would like to add...
2
by: Lee | last post by:
I have a Word template that is set to merge with our client database. After I run the merge, I merge to a new document, and then save the new document. When I reopen this saved document, it prompts...
2
by: Darryl Kerkeslager | last post by:
As the subject above hopefully makes clear, I want to do several reports, "with lots of fields not otherwise in database". These reports also have variable-length text. I have defined the...
4
by: RSH | last post by:
Hi, I have a situation where I have created a little application that makes an Access database from a SQL Database for reporting purposes. it does the job well, but it seems a bit slow. Is...
3
by: vonclausowitz | last post by:
Hi All, I was thinking of creating a table in my database to index all words in the database. That way I can quickly search for one or more words and the index table will return the words and...
3
by: AccessThis | last post by:
Hi everyone, I’m fairly new to Access and VBA, but I have set up the following code to export all the records in my database to a word template (C:\Template.dot) with bookmarks (bkfield1,...
2
by: raamay | last post by:
i have seen various tutorials on how to search a database but havent found one which teaches how to search a word or a string anywhere in a database. Well, a user may type 'hel' in the search box and...
13
by: hedges98 | last post by:
Hello I have a letter template in Word that has some blanks. I want to populate these blank spaces with fields from the database. These blanks are: client name client address appointment date...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.