I'm trying to open a word document from access and enter some data from my access form into the document. ...
Can anyone help?
Hi icthus123...
I am pretty new at this, and haven't taken text from Access to Word before. So I played around a little bit. Assuming a single text field called txtMemo that we want to import into a new Word Document. the code I generated to take that data into MSWORD in a new document is as follows.
-
Private Sub cmdWord_Click()
-
On Error GoTo Err_cmdWord_Click
-
-
Dim objWord As Object
-
Dim objPrintout As String
-
-
objPrintout = Me.txtMemo.Value
-
Set objWord = CreateObject("Word.Application")
-
objWord.Visible = True
-
objWord.Documents.Add
-
objWord.Selection.TypeText objPrintout
-
-
Exit_cmdWord_Click:
-
Exit Sub
-
-
Err_cmdWord_Click:
-
MsgBox Err.Description
-
Resume Exit_cmdWord_Click
-
-
End Sub
This worked for me for one text box. I haven't played with how to loop through to get the data from multiple places, but that part should be fairly simple if you just change the variable on each loop to take the data from multiple fields. You can concatenate as normal and even set formatting options, and the syntax for those formatting options should be readily available online.
Let me know how it goes! If you can't get it to work, let me know and we'll see what we can figure out :)
theAybaras