Hi folks;
Hey wow! First post! Hope it bears fruit... Anyway, I've been teaching myself Access since March by writing an event/contact management database for the firm I work for. It's reasonably straightforward , it just records details on our clients among other thihgs. The old Lotus DB it (supposedly!) supercedes had a handy feature that I've so far had no luck in replicating in Access. It worked as follows:
1. The user browsed to a Client Contact record, which contained all of an individual person's contact data stored as separate fields.
2. The user could then click a handy button on the Contact form that would automatically capture the text from the relevant fields, collate it, and plonk them as an address block into the top of an automatically opened text document.
3. The user could then type a letter to the contact below the address as usual. When the time came to print the letter the address block would be in just the right place to be visible through a windowed envelope.
That's about it really. I've had a long search and found many ways to export from Access to Word, or import from to Word from Access, but none of them are so simple or straightforward . I know this must be possible somehow, but does anybody know how? The best I've been able to do so far is insert a button on the form that runs a query and displays the fields I picked in a table that pops up, but that's it.
I'm not an Access pro and I don't know how to code, so any replies starting with "Simple, just fire up C++ and xyz...." will probably leave me in tears! I'm fine with macros and queries and Microsoft packages in general, so if anyone has any ideas I'd love to hear them.
Thanks guys!
10 2937
Hi folks;
Hey wow! First post! Hope it bears fruit... Anyway, I've been teaching myself Access since March by writing an event/contact management database for the firm I work for. It's reasonably straightforward , it just records details on our clients among other thihgs. The old Lotus DB it (supposedly!) supercedes had a handy feature that I've so far had no luck in replicating in Access. It worked as follows:
1. The user browsed to a Client Contact record, which contained all of an individual person's contact data stored as separate fields.
2. The user could then click a handy button on the Contact form that would automatically capture the text from the relevant fields, collate it, and plonk them as an address block into the top of an automatically opened text document.
3. The user could then type a letter to the contact below the address as usual. When the time came to print the letter the address block would be in just the right place to be visible through a windowed envelope.
That's about it really. I've had a long search and found many ways to export from Access to Word, or import from to Word from Access, but none of them are so simple or straightforward . I know this must be possible somehow, but does anybody know how? The best I've been able to do so far is insert a button on the form that runs a query and displays the fields I picked in a table that pops up, but that's it.
I'm not an Access pro and I don't know how to code, so any replies starting with "Simple, just fire up C++ and xyz...." will probably leave me in tears! I'm fine with macros and queries and Microsoft packages in general, so if anyone has any ideas I'd love to hear them.
Thanks guys!
refine your search to something called a mail merge. it's not quite so push button as the old school stuff...but it's doable.
www.msdn.com (search for Access mail merge) that will give you an idea of what it's all about. Easier than me trying to type or paste it all in I think.
J
Thanks for the info J, all helpful stuff. I've hit another stumbling block though! After having trawled most of the charted Internet for an answer it's still sticking. The maddening thing is that I can see it working with jut a few tweaks, but because I don't really "understand " the inner workings of VB all I can do is poke around and see what happens.
So far I have the following code attached to the Click event of the Mail Merge button on my Access form:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("S:\G RADUATIONS\Know ledge Management Database\Mark 2\mergedoc.doc" , "Word.Document" )
' Make Word visible.
objWord.Applica tion.Visible = True
' Set the mail merge data source as the current database.
objWord.MailMer ge.OpenDataSour ce _
Name:=CurrentDb .Name, _
LinkToSource:=T rue, _
Connection:="TA BLE tblContactDetai ls", _
SQLStatement:=" Select firstname,lastn ame,jobtitle,de partment,addres s1,address2,add ress3,city,look upcounties,post code,country from tblContactDetai ls WHERE ContactID=[frmContactDetai ls!contactID]"
' Execute the mail merge.
objWord.MailMer ge.Execute
End Function
It's more or less copied from the MSDN article but with a few tugs to point it to the correct files. I think the problem is with my SQL statement. I can't find a way to make it pick only the address details on the current form rather than the entire database. I'm not sure it's allowing me to address "ContactID=[frmContactDetai ls!contactID]" as a valid WHERE statement. The original MSDN article had the SQL statement SQLStatement:=" Select * from [table]", but that outputs every record in the table to Word and that's not what I need!
Anyway, if anybody has any ideas I'd love to hear them!
Hen
ADezii 8,834
Recognized Expert Expert
Thanks for the info J, all helpful stuff. I've hit another stumbling block though! After having trawled most of the charted Internet for an answer it's still sticking. The maddening thing is that I can see it working with jut a few tweaks, but because I don't really "understand " the inner workings of VB all I can do is poke around and see what happens.
So far I have the following code attached to the Click event of the Mail Merge button on my Access form:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("S:\G RADUATIONS\Know ledge Management Database\Mark 2\mergedoc.doc" , "Word.Document" )
' Make Word visible.
objWord.Applica tion.Visible = True
' Set the mail merge data source as the current database.
objWord.MailMer ge.OpenDataSour ce _
Name:=CurrentDb .Name, _
LinkToSource:=T rue, _
Connection:="TA BLE tblContactDetai ls", _
SQLStatement:=" Select firstname,lastn ame,jobtitle,de partment,addres s1,address2,add ress3,city,look upcounties,post code,country from tblContactDetai ls WHERE ContactID=[frmContactDetai ls!contactID]"
' Execute the mail merge.
objWord.MailMer ge.Execute
End Function
It's more or less copied from the MSDN article but with a few tugs to point it to the correct files. I think the problem is with my SQL statement. I can't find a way to make it pick only the address details on the current form rather than the entire database. I'm not sure it's allowing me to address "ContactID=[frmContactDetai ls!contactID]" as a valid WHERE statement. The original MSDN article had the SQL statement SQLStatement:=" Select * from [table]", but that outputs every record in the table to Word and that's not what I need!
Anyway, if anybody has any ideas I'd love to hear them!
Hen
'Assuming [ContactID] is a Numeric Value: - objWord.MailMerge.OpenDataSource _
-
Name:=CurrentDb.Name, _
-
LinkToSource:=True, _
-
Connection:="TABLE tblContactDetails", _
-
SQLStatement:="Select firstname,lastname,jobtitle,department,address1,ad dress2,address3,city,lookupcounties,postcode,count ry from tblContactDetails WHERE ContactID=" & Forms![frmContactDetails]![ContactID]
It is indeed a numeric value, I'll give that a try right now! Here goes... What does the & character do in an SQL query anyway?
Well, it's definitely an improvement! The old query string would output all 1000 or so records to Word, the new one only outputs one record. The only trouble is that this is what comes out when the Word .doc opens up:
1 1
1
1
1
1
1
1
1
1
1
Previously it would output
{page 1}
1 1
1
1
1
1
1
1
1
1
1
{page 2}
2 2
2
2
2
2
2
2
2
2
2
{page 3}
3 3
3
3
3
3
3
3
3
3
3
And so on... At least the numbers are appearing on top of the merge fields in the Word .doc (2 fields on first line, 1 on the remainder) but the actual content of the fields doesn't seem to be surviving the translation... How odd. Any ideas?
Anyone have any more ideas on this before I plunge my head into boiling oil and end it all?
Thanks!
ADezii 8,834
Recognized Expert Expert 'Assuming [ContactID] is a Numeric Value: - objWord.MailMerge.OpenDataSource _
-
Name:=CurrentDb.Name, _
-
LinkToSource:=True, _
-
Connection:="TABLE tblContactDetails", _
-
SQLStatement:="Select firstname,lastname,jobtitle,department,address1,ad dress2,address3,city,lookupcounties,postcode,count ry from tblContactDetails WHERE ContactID=" & Forms![frmContactDetails]![ContactID]
It concatenates, appends, adds to as in:
"John" & " " & "Doe" ==> John Doe
Aha! I've cracked it! The plums from the support site where I got instructions for preparing the Word document had gotten it all wrong. They'd told me to have each field in the Word .doc marked as a MergeRec field, which simply places a marker in the .doc for Access to place the relevant record number. Geniuses. I changed them all to MergeField fields and now it works fine. Thanks all!
Can anybody tell me how I can get a sub form which displays data from a table to export the rows to a Word Document? I tried the lines in the post above this. But I'm getting a few errors related to Object Variable. I'm new to Access and I don't have a clue. Please help.
Could you also please tell me how I can make these values appear in the Word Document wherever I want?? I need help in setting the markers.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jayjay |
last post by:
Is it possible to export a report to word and have it include the
graphics that are in the report?
I'd like to take some of our reports and export them to word so we can
email those to the client, but when I export, I lose the logo as well
as any graphics (grey line separaters, etc) and only get the text of
the reports.
|
by: Fran Zablocki |
last post by:
I have a process that exports an Access table to a comma-delimited
text file. One of the fields that is exported shows the date it was
exported, using the Date() function. In the Access table, the date
appears in the records in mm/dd/yyyy format, but after exporting, the
date appears as mm/dd/yyyy 0:00:00. For example, today is 11/06/2003.
It shows 11/06/03 in the Access table, but the exported text file
shows 11/6/03 0:00:00. I thought...
|
by: D |
last post by:
I've created a report with many subreports of aggregate data. I want my
client to be able to export this data to Excel to make her charts, etc. Only
one problem: one of the fields is a "SchoolYear" TEXT field that contains
data such as 2000/01, 2001/02, etc. If I export a Query with this kind of
data to Excel, it gives me the text value of this field; however, when I
export a Report bound to this TEXT field, Excel gives me the values 36526,...
|
by: Paolo |
last post by:
Friends, I have a problem with my Access database when trying to
export data from a form to a Word file.
I use a form to store data in a table. Both table and form are named
CONTACT.
I use a Module to export data into a Word document. I use bookmarks in
Word and have noticed that although I have set my table's field
properties to Capital Letters (>), is type the text into the field on
my form, when I exported to my Word file, it is...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
| |
by: Otis Hunter |
last post by:
I have been given an Access Database which contains a table that has
an OLE object field that contains a Word document. That table contains
hundreds of records. I would like to find out how I can write a VB
script, to be executed either within Access or executed at the CMD
prompt, which will loop through all the records and open the document
object and save it to a Word document that I can access from Windows
Explorer. An additional info...
|
by: Otis Hunter |
last post by:
I have been fighting with this for days and your expert help is
needed! Below is the code I am executing which results with "Object
doesn't support this property or method". The error is occuring on
the "With Me.OLEObject" line. I am trying to extract a Word
document(OLE object) from an Access database, for each record in the
table, and save it as a Word Document. The 4th field of each record
is a OLE object type.
I may be getting...
|
by: Access Newbie with a headache via AccessMonster.co |
last post by:
I am looking to export certain variables from ms access to ms word, Does
anyone have any idea how this is done. So far my function collects data from
two separate tables, and can open the word document that I need, but I am
unable to figure out how to make it write the collected data to the new word
document. Any help would be great.
Public Sub ShipmentRequest_Click()
Dim inv As Double
Dim getINV As String
|
by: no8do |
last post by:
Hi there,
I am brand new in access and VBA programming and I am asking for your help. One of the fields in my db is of the OLE object data-type. I' ve written a vb script that is executed on a button's click on my form for openning an embedded word document, on which I can write text. The text is saved on the field as soon as I close the word document. For the record, the code that I use is the following:
A.Class = "Word.Document" ' Set...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |