View Single Post
 
Old 01-07-2014, 02:38 PM
mhblake mhblake is offline Windows XP Office 2007
Novice
 
Join Date: Dec 2013
Posts: 5
mhblake is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
I suggest you employ a userform for initially creating the document:

http://gregmaxey.com/word_tip_pages/..._userform.html
Thanks Greg.

I think I'm about 90% there following your instructions, but I think I'm missing something because it doesn't quite work :/

I have a form with 3 text boxes (GrpName, PriorPY, CurrentPY) and two combo boxes (PYMonth1, PYMonth2).

The trouble I'm experiencing is trying to get the data entered in the form into the document. Here's what I have (the "var" reference in VBA matches the field in the word document)

Code:
Option Explicit
Sub AutoNew()
  Create_Reset_Variables
  CallUF
lbl_Exit:
Exit Sub
End Sub
Sub CallUF()
Dim oFrm As frmSurvey
Dim oVars As Word.Variables
Dim strTemp As String
Dim oRng As Word.Range
Dim i As Long
Dim strMultiSel As String
  Set oVars = ActiveDocument.Variables
  Set oFrm = New frmSurvey
  With oFrm
    .Show
      oVars("varGrpName").Value = .txtGrpName
      oVars("varCurrentPY").Value = .txtCurrentPY
      oVars("varPriorPY").Value = .txtPriorPY
      oVars("varPYMonth1").Value = .txtPYMonth1
      oVars("varPYMonth2").Value = .txtPYMonth2
    Else
      MsgBox "Form cancelled by user"
    End If
  End With
  Unload oFrm
  Set oFrm = Nothing
  Set oVars = Nothing
  Set oRng = Nothing
lbl_Exit:
  Exit Sub
End Sub
Anything that jumps out here? I don't need any validation, etc... I just need the data to flow into the document.

Many thanks!
Reply With Quote