473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening Word Document and passing information to next new line

I want to open a word document from an Access form and transfer data
from the Access form to the Word Document.

For instance, if a user clicks an option box on my access form, I want
to pass certain data to the next new line of a opened word doc.

Here is what I tried, but doesnt seem to work:

Dim objWord As Object
Dim NewRow As Row

Set objWord = CreateObject("W ord.Application ")

objWord.Visible = True
objWord.Documen ts.Open "U:\May 6.doc"

Set NewRow = objWord.Tables( 1).Rows.Add
With NewRow
.Cells(1).Range .Text = Format(Now(), "HH:MM") & " " & "HRS PD"
.Cells(2).Range .Text = "Police on property at this time."
End With

Thanks,
Brian

May 7 '06 #1
2 3359
Here is a function I use, and it works fine.

You really should define bookmarks in a Word template, like: name,
address, zip code, city etc.

Now, in the form you should call this function by:

Private Sub cmdMergeWithWor d_Click()
On Error GoTo Err_FW
Dim strM As String
strM = DLookup("[LetterPat]", "tblFirmaIn fo", "[FirmaID] = 1")
MakeAWordDoc strM
Exit_FW:
Exit Sub
Err_FW:
MsgBox Err.Number & " " & "CUSTOMER/FW" & Chr(13) _
& Err.Description , vbOKOnly
Resume Exit_FW
End Sub
Here is the function(In it's own module):

Public Function MakeAWordDoc(By Val strFile as String)
On Error Resume Next
Dim dbMTW As DAO.Database
Dim rsMTW As DAO.Recordset
Dim strKUNUM, strKUNAVN, strKUADRESS, strPNR, strSTD, strVR As String
Dim Wordobj As Word.Applicatio n
strKUNUM = DLookup("[Custnr]", "tblCustome r", "[CustID] = " &
Forms!frmCustom er!CustID)
strKUNAVN = UCase(DLookup("[AName]", "tblCustome r", "[CustID] = " &
Forms!frmCustom er!CustID))
strKUADRESS = UCase(DLookup("[Adress]", "tblustomer ", "[CustID] = " &
Forms!frmCustom er!CustID))
strPNR = DLookup("[Postnr]", "tblPostnr" , "[PostnrID] = " &
Forms!frmCustom er!PostnrID)
strSTD = DLookup("[Sted]", "tblPostnr" , "[PostnrID] = " &
Forms!frmCustom er!PostnrID)
strVR = DLookup("[VaarRef]", "tblFirmaIn fo", "[FirmaID] = 1")
Set dbMTW = CurrentDb()
Set rsMTW = dbMTW.OpenRecor dset("tblCustom er", dbOpenTable)
rsMTW.Index = "PrimaryKey "
rsMTW.Seek "=", Forms!frmCustom er!CustID
'If rsMTW.NoMatch Then
'MsgBox "Did not find a customer with that name!", vbOKOnly
'Exit Function

'End If
DoCmd.Hourglass True
Set Wordobj = GetObject(, "Word.Applicati on")
If Err.Number <> 0 Then
Set Wordobj = CreateObject("W ord.Application ")
End If
Wordobj.Visible = True
Wordobj.Documen ts.Add _
Template:=strFi le, _
NewTemplate:=Fa lse
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="KNR"
Wordobj.Selecti on.TypeText "K.nr.: " & strKUNUM
'UCase(rsMTW![Custnr])
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="NAVN"
Wordobj.Selecti on.TypeText strKUNAVN
'UCase(rsMTW![AName])
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="ADRESS"
Wordobj.Selecti on.TypeText strKUADRESS
'UCase(rsMTW![Adress])
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="POSTNR"
Wordobj.Selecti on.TypeText strPNR
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="STED"
Wordobj.Selecti on.TypeText UCase(strSTD)
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="DR"
Wordobj.Selecti on.TypeText "Deres ref.: " & UCase(rsMTW![Referanse])
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="VR"
Wordobj.Selecti on.TypeText "Vår ref.: " & UCase(strVR)
Wordobj.Selecti on.GoTo what:=wdGoToBoo kmark, name:="DT"
Wordobj.Selecti on.TypeText Date

DoEvents
Wordobj.Activat e

Set Wordobj = Nothing
DoCmd.Hourglass False

Exit Function
TemplateError:
Set Wordobj = Nothing
Exit Function

End Function
BerkshireGuy skrev:
I want to open a word document from an Access form and transfer data
from the Access form to the Word Document.

For instance, if a user clicks an option box on my access form, I want
to pass certain data to the next new line of a opened word doc.

Here is what I tried, but doesnt seem to work:

Dim objWord As Object
Dim NewRow As Row

Set objWord = CreateObject("W ord.Application ")

objWord.Visible = True
objWord.Documen ts.Open "U:\May 6.doc"

Set NewRow = objWord.Tables( 1).Rows.Add
With NewRow
.Cells(1).Range .Text = Format(Now(), "HH:MM") & " " & "HRS PD"
.Cells(2).Range .Text = "Police on property at this time."
End With

Thanks,
Brian


May 8 '06 #2
Thank you for the response!

Works well.

-Brian

May 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
268
by: Novice | last post by:
Hi all, I'm a novice VB.NET and VBA programmer and am wondering if there is a tutorial out there on how to create a word document based on data in a database and then return that document to a web user. I'm using Visual Studio .Net 2003 for my IDE I am familiar enough with VBA to be able to write all the code to generate the document, it is...
0
4903
by: Sivaraman.S | last post by:
Issue : When I am trying to open a Word Document or a Template from a Web Application (ASP.NET Web page - Language Used VB.NET Visual Studio Version 2003) using Word.ApplicationClass (Refering Word 11.0 Library), I am getting the following Errror: Could not open Macro storage. (System.Runtime.ComExeception) When I am Opening the word...
3
2412
by: John | last post by:
Hi I am using the code given at the end to open a word document from within vb.net. It works fine the first time but the second time I get the error; Unhandled Exception: System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. at Word.ApplicationClass.get_Documents() The error occurs on the line WordDoc...
1
2145
by: ourspt | last post by:
Hi, We are working on an ASP.NET (VB.NET) application and we have a problem opening a word document from our application. When we try to open the word document, we do not get any error message but the system hangs.
7
3205
by: mkorch17 | last post by:
Hello, I have a server with a Word document and an Access database on it. I also have an ASP page running on the server. The Word document contains a mail merge with the Access database. What I want to do is open the merged Word document from the ASP page when a button is clicked. I have tried several things including some scripting...
3
4876
by: Csaba Gabor | last post by:
If I do not have the indicated Word document open (on my Win XP Pro machine with PHP 5.2), the following will open and display it: <?php $path = "c:\\path\\to\\word\\document\\mydoc.doc"; $doc = new COM($path); $doc->Application->visible = true; ?> However, there will be several identical warnings (14 in number)
3
1300
by: =?Utf-8?B?ZWQ=?= | last post by:
Windows xp: When I try to open a word document, I get the message that "a dialogue box is open, close the dialogue box and try again." I don't know what to do. I don't have word, but I have downloaded the software allowing me to read word. please give lost of detail I am new to this. ed
0
1625
by: AparnaKulkarni | last post by:
Hello, I m working with Templates in MS Word. I have established the user Template locations in Word with ".dot" file But after that I m getting error as "Invalid procedure call or argument (Error 5)" while opening any Word Document. Can anyone tell me about why it is coming like? I think that the problem is with the code in Project to be...
0
1005
theBond
by: theBond | last post by:
HI! I am trying to open word document on server through c# from client web interface but i am not getting success. can anyone guide me on how can i open doc file which is on server through web based interface from client machine theBond
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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...
0
7964
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 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...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.