Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open word and give it the value of access control form 1

Status
Not open for further replies.

MrBaRRon

Programmer
Aug 8, 2003
39
IT
Hi everybody,

I want to create a word document from ACCESS ( when the user click on a button within the ACCESS form ). The code I want to make must create a table in this new document with a number of lines that depend of the value that user putted in the form.

By example, if the user put 45, the table within the new document must have 45 lines.

So the question is how to open word and how to give to word the value that the user wrote .

Thank U.

 
Here is a start for you. Note that to create a table in Word there MUST be a value for columns. This example puts it at one. This assumes a textbox on the form named Textbox1

Code:
Private Sub CommandButton1_Click()
Dim wrd As Word.Application
Dim i As Integer
Dim r As Range
Dim intNumRows As Integer

intNumRows = TextBox1.Value
' create instance of Word
Set wrd = GetObject(, "Word.Application")

' create new doc & add one paragraph mark
wrd.Documents.Add
Selection.TypeParagraph
' set a range object
Set r = ActiveDocument.Content
r.Collapse Direction:=wdCollapseEnd
ActiveDocument.Tables.Add Range:=r, NumRows:=intNumRows, NumColumns:=1
wrd.Visible = True
Set r = Nothing
Set wrd = Nothing
Unload Me
End Sub

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top