Creating Doc from Access (1 Viewer)

kapil

Registered User.
Local time
Tomorrow, 03:07
Joined
Oct 4, 2006
Messages
17
Hi,

I have created an Access Form wherein i take the user input in various text boxs and text areas.

Now plz help me to find out how to create Microsoft Word Document automatically from the information which the user has submitted.

I have provided a button named submit which when clicked will submit the information into the Access Database and using that data i want to create a Word Document into a particular format.

What is the way in which this could be achieved?

Please help me out to find a solution to this problem.

Thanking you,

with regards,
Kapil
 

Ron_dK

Cool bop aficionado
Local time
Today, 23:37
Joined
Sep 5, 2002
Messages
2,141
You might do a search for merge it with word.
Assuming the data on your form is based on a table or query, you can export that data to a word document.
In access there is a function called merge with MsWord.
Try that one.

Hth
 

Johny

Registered User.
Local time
Today, 23:37
Joined
Jun 1, 2004
Messages
80
Or you can create a word template, add some bookmarks in it and write your user input to those bookmarks, creating a new doc based on this template.
Haven't tried this, but I think it would work
 

ansentry

Access amateur
Local time
Tomorrow, 07:37
Joined
Jun 1, 2003
Messages
995
kapil,

Have a look at my samples posted HERE, 1 is for Single Bookmark and the other Multiple. Read the "readme.txt"first.

The code in the sample will only create a word document for the current record on screen.

Johny was on the right track
 

Tezcatlipoca

Registered User.
Local time
Today, 22:37
Joined
Mar 13, 2003
Messages
246
Johny said:
Or you can create a word template, add some bookmarks in it and write your user input to those bookmarks, creating a new doc based on this template.
Haven't tried this, but I think it would work


Indeed it does, since I use it in a small database I wrote for work. Assuming you want this to function at the click of a button, use the following code as the OnClick property of the button:

Code:
Private Sub cmdSend_Click()
    Beep
    Select Case MsgBox("Create a Document?" & vbCrLf, vbYesNo + vbQuestion, "Create Document")
        Case vbYes:
   
   '*****************************
   'START OF FORM PRODUCTION CODE
   '*****************************
   
   ' Create a Word document from template.
   Dim WordApp As Word.Application
   Dim strTemplateLocation As String
  
   ' Specify location of template
   strTemplateLocation = "[COLOR="Red"][B]C:\EXAMPLE\EXAMPLE.DOT[/B][/COLOR]"
    
    
   On Error Resume Next
   Set WordApp = GetObject(, "Word.Application")
   If Err.Number <> 0 Then
     Set WordApp = CreateObject("Word.Application")
   End If
   On Error GoTo ErrHandler
   
   
   WordApp.Visible = True
   WordApp.WindowState = wdWindowStateMaximize
   WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
    
   ' Replace each bookmark with field contents.
   With WordApp.Selection
   
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmark1[/B][/COLOR]"
     .TypeText [[B][COLOR="Red"]form-field1[/COLOR][/B]]
   
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmark2[/B][/COLOR]"
   ' If the Access form field is blank, fill the bookmark with something else
     If IsNull(rmalogged) Then
       .TypeText "[COLOR="Red"][B]WHATEVER[/B][/COLOR]"
     Else
       .TypeText [[COLOR="Red"][B]form-field2[/B][/COLOR]]
     End If
     
   ' Finish by putting the cursor to the top of the template letter
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmarktop[/B][/COLOR]"
     .TypeText " "
    
   End With
    
   DoEvents
   WordApp.Activate
    
   Set WordApp = Nothing

ErrHandler:
Set WordApp = Nothing
      
   '***************************
   'END OF FORM PRODUCTION CODE
   '***************************
 
        Case vbNo: 'Do not save or undo
            'Do nothing

        'Case vbCancel: 'Undo the changes
            'DoCmd.RunCommand acCmdUndo
            'Me.tbProperSave.Value = "No"

        Case Else: 'Default case to trap any errors
            'Do nothing

    End Select
End Sub


You will need to do two things prior to this code working. Firstly, you will need to setup a template in Word and establish however many bookmarks you require into it. Once done, save it in a secure location on your PC.
Secondly, you'll need to alter all those sections of code that appear in bold red to suit your own needs. It is vital that your bookmarks share the same name as those listed under the Name:="X" section of the code. If you need any more help, just let me know.
 
Last edited:

kapil

Registered User.
Local time
Tomorrow, 03:07
Joined
Oct 4, 2006
Messages
17
Rich Text to Word

Hi...

Thanks a lot for the response...

I would like to know that when i am passing the values from Access Forms to Word by creating bookmarks then will the Rich Text retained in that...
All the tab information, Table Creation, etc.
Will all these rich text information retained when i try to pass them from Form to Word....

Thanking you,
Kapil
 

ansentry

Access amateur
Local time
Tomorrow, 07:37
Joined
Jun 1, 2003
Messages
995
Thanks a lot for the response...

I would like to know that when i am passing the values from Access Forms to Word by creating bookmarks then will the Rich Text retained in that...
Who are you asking this question of?

Rich text is not used, the formatting is done in word, did you try my sample?
 

kapil

Registered User.
Local time
Tomorrow, 03:07
Joined
Oct 4, 2006
Messages
17
Rich Text to Word

ansentry said:
Who are you asking this question of?

Rich text is not used, the formatting is done in word, did you try my sample?


Ya i did try ur application.. It was working perfectly fine...

What my question here was.. In the Access Form what i have done is that i have included a Rich Text Format ActiveX Control..
This control enables me to give Rich Text into the Access Form... Most of the Word Processing Formats....

Now i have included a BookMark in the Word Document...
What i want is that this entire Rich Text Information which i have given via Access Forms is retained there in the Word Document as it is...

In the Application which u gave comprised of simple text.. Just that in place of just simple text i want to give Rich Text as input and that is retained as it is in the Word Document and is not lost in the way...

That was my question.. I hope i have been able to explain it to you..

Thanking you,
Kapil
 

ansentry

Access amateur
Local time
Tomorrow, 07:37
Joined
Jun 1, 2003
Messages
995
i have included a Rich Text Format ActiveX Control..

Sorry, I'm unable to assist you as I have never used "Rich Text Format ActiveX Control"

Someone else may be able to assist.
 

johndoomed

VBA idiot
Local time
Today, 14:37
Joined
Nov 4, 2004
Messages
174
This was a great thread!

But I do have one more question. Is it possible to save a document in a specific location, with a filename based on date and Costumername? And ofcourse save this filename in access?
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 14:37
Joined
Nov 8, 2005
Messages
3,294
Yes - look through the samples something done by ghudson
has a very smart function of making a directory on a server and creating a folder -
you can use this as the starting place
 

bwyrwitzke

Registered User.
Local time
Today, 22:37
Joined
Nov 11, 2002
Messages
50
Indeed it does, since I use it in a small database I wrote for work. Assuming you want this to function at the click of a button, use the following code as the OnClick property of the button:

Code:
Private Sub cmdSend_Click()
    Beep
    Select Case MsgBox("Create a Document?" & vbCrLf, vbYesNo + vbQuestion, "Create Document")
        Case vbYes:
   
   '*****************************
   'START OF FORM PRODUCTION CODE
   '*****************************
   
   ' Create a Word document from template.
   Dim WordApp As Word.Application
   Dim strTemplateLocation As String
  
   ' Specify location of template
   strTemplateLocation = "[COLOR="Red"][B]C:\EXAMPLE\EXAMPLE.DOT[/B][/COLOR]"
    
    
   On Error Resume Next
   Set WordApp = GetObject(, "Word.Application")
   If Err.Number <> 0 Then
     Set WordApp = CreateObject("Word.Application")
   End If
   On Error GoTo ErrHandler
   
   
   WordApp.Visible = True
   WordApp.WindowState = wdWindowStateMaximize
   WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
    
   ' Replace each bookmark with field contents.
   With WordApp.Selection
   
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmark1[/B][/COLOR]"
     .TypeText [[B][COLOR="Red"]form-field1[/COLOR][/B]]
   
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmark2[/B][/COLOR]"
   ' If the Access form field is blank, fill the bookmark with something else
     If IsNull(rmalogged) Then
       .TypeText "[COLOR="Red"][B]WHATEVER[/B][/COLOR]"
     Else
       .TypeText [[COLOR="Red"][B]form-field2[/B][/COLOR]]
     End If
     
   ' Finish by putting the cursor to the top of the template letter
     .GoTo what:=wdGoToBookmark, Name:="[COLOR="Red"][B]bookmarktop[/B][/COLOR]"
     .TypeText " "
    
   End With
    
   DoEvents
   WordApp.Activate
    
   Set WordApp = Nothing

ErrHandler:
Set WordApp = Nothing
      
   '***************************
   'END OF FORM PRODUCTION CODE
   '***************************
 
        Case vbNo: 'Do not save or undo
            'Do nothing

        'Case vbCancel: 'Undo the changes
            'DoCmd.RunCommand acCmdUndo
            'Me.tbProperSave.Value = "No"

        Case Else: 'Default case to trap any errors
            'Do nothing

    End Select
End Sub


You will need to do two things prior to this code working. Firstly, you will need to setup a template in Word and establish however many bookmarks you require into it. Once done, save it in a secure location on your PC.
Secondly, you'll need to alter all those sections of code that appear in bold red to suit your own needs. It is vital that your bookmarks share the same name as those listed under the Name:="X" section of the code. If you need any more help, just let me know.


This is great. Any idea if it will work with nested sub-forms?
 

Users who are viewing this thread

Top Bottom