473,405 Members | 2,282 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,405 software developers and data experts.

Need Programming help in MS Word

3
I have encountered a problem with some of one of my access databases due to a rollout of security patches and etc at my company. I have an access database that dumps data into a word template. The template contains instructions for filling out the rest of the needed information. I have a button on the word document with caption that says "remove instructions" at that point, I have word try and copy all of the text out of the document with proper formatting into a new word document that has no macros/code behind the scene for a user to fill in their information and save.

Here is the code:

Option Explicit
Dim objword As Object, ObjWordApp As Object, strName As String, aDoc As Document
__________________________________________________ _______________
Public Sub Document_New()
On Error GoTo errorhandler

Set objword = ActiveDocument

objword.MailMerge.OpenDataSource _
Name:="C:\DbWork\LtrRes.accde", _
LinkToSource:=True, _
Connection:="QUERY qryDocument", _
SQLStatement:="Select * from [qryDocument]"

' Execute the mail merge.
objword.MailMerge.Execute
objword.Close (0)

errorhandler:
If Err.Number > 0 Then
MsgBox "Data was not pulled for this template. Please use this blank template to manually fill in fields."
End If
End Sub
__________________________________________________ _______________
Private Sub CommandButton1_Click()
With ActiveDocument.Content.Find
With Selection.Find
.ClearFormatting
.Font.Color = wdColorTeal
.Replacement.ClearFormatting
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll, Forward:=True, _
Wrap:=wdFindContinue
End With
End With

DeleteThis

End Sub

__________________________________________________ ________________
Private Sub DeleteThis()
Dim o As Object
'ActiveDocument.ToggleFormsDesign
For Each o In ActiveDocument.InlineShapes
If o.OLEFormat.Object.Caption = "Remove Instructions" Then
o.Delete
End If
Next

strName = ActiveDocument.Name
CopyDoc (strName)

Documents(strName).Close (0)
End Sub

__________________________________________________ ________________
Public Sub CopyDoc(DocName As String)

Documents(DocName).Range.StartOf Unit:=wdSection, Extend:=wdExtend
Documents(DocName).Range.MoveEnd Unit:=wdSection
Documents(DocName).Select
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdFormatOriginalFormatting)

End Sub


Basically what happens is it just crashes out and nothing gets copied into the new word document. Any help would be greatly appreciated. Let me know if you need anymore deatils
Apr 28 '10 #1
1 2190
hidust
3
Microsoft Word crashes when its trys to run the:
Documents(strName).Close (0)

Any thoughts anyone?
Apr 29 '10 #2

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

Similar topics

45
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
38
by: BORT | last post by:
Please forgive me if this is TOO newbie-ish. I am toying with the idea of teaching my ten year old a little about programming. I started my search with something like "best FREE programming...
2
by: bekil | last post by:
I have a problem with landscape pages in word document. I am creating a word document using asp programming. I want to set n. page as a landscape. But I can not do it. for example I want to...
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
7
by: Michael | last post by:
Hey, I'm, I guess, an itermediate programmer and I have a question about learning any programming language. I understand that as a programmer you're going to probably constantly be re-writing code...
9
by: perry.yuan | last post by:
Hi there, I got a problem: how to return an lvalue from conditional expression in C programming language. Any solution or suggestion to my problem in either C or C++ is welcome. On the CPU...
4
by: Nick Halstead | last post by:
Want to test your PHP programming skills? I have just launched a PHP programming contest on my blog. The problem Many years ago there used to be a UK television quiz show (I am sure there has...
2
by: signal2007 | last post by:
Hi everyone,how are you? What are some functions of a word processor in C/C++ programming?in other word how can i program a small word processor by c/c++? thanks in advance
5
by: av3rage | last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get...
0
by: athirukk | last post by:
Hi, I am doing Office (Word) programming in .Net with Microsoft.Office.Interop.Word. My C# code highlights the a text range in a Word document with the following snippet. ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.