By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,877 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,877 IT Pros & Developers. It's quick & easy.

VB 6.3/Word 2003 Problem updating specific variables

P: 3
Hi!

I have a word template that utilizes a userform to gather information from the user and place it into specific Doc Variable locations within the form. If the user reopens the userform and updates the information all of the form fields are reset. My question is: How can I have only the Doc Variable information updated and not the rest of the form fields?

My user form code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Sub cmdCancel_Click()
  4.   Unload Me
  5. End Sub
  6.  
  7. Private Sub cmdOK_Click()
  8.   ' Prevent variable from being deleted
  9.   If txtDate = "" Then txtDate = " "
  10.   ActiveDocument.Variables("Date") = txtDate
  11.   If txtClientName = "" Then txtClientName = " "
  12.   ActiveDocument.Variables("Client Name") = txtClientName
  13.   If txtClientIDNumber = "" Then txtClientIDNumber = " "
  14.   ActiveDocument.Variables("Client ID Number") = txtClientIDNumber
  15.   ' Update fields in document
  16.   ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update
  17.   ActiveDocument.Fields.Update
  18.   Unload Me
  19. End Sub
  20.  
  21. Private Sub Userform_Initialize()
  22.   ' Load variables into text boxes
  23.   On Error Resume Next
  24.   txtDate = ActiveDocument.Variables("Date")
  25.   txtClientName = ActiveDocument.Variables("Client Name")
  26.   txtClientIDNumber = ActiveDocument.Variables("Client ID Number")
  27. End Sub
I have am new to VBA so any guidence on this would be a big help.

=),
Ducky
Jul 27 '07 #1
Share this Question
Share on Google+
1 Reply


P: 3
Oh, I figured out what the code was missing! I have it working now =).

=),

Ducky
Jul 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.