![]() |
#1
|
|||
|
|||
![]()
I am trying to create a Userform for a Contract Template and it is not quite right and have been racking my brain to figure out where I went wrong.
I have the Userform Sorted out, and works when I input the data and Press OK - CommandButton1. However, when I click cancel (CommandButton2) it comes up with an error in the code. I have included the whole code below so someone can have a look and help me fix it. In addition to this problem, the macro doesnt work. Both when I open up a new template from this Document as well as going into Macro itself and running it. Please help me. Code:
Option Explicit Private oVars As Variables Private Sub Userform_Click() End Sub Private Sub UserForm_Initialize() Me.Caption = "Contract Extension Template" Me.TextBox1.Value = "Management Company Name" Me.TextBox2.Value = "Contractor Name" Me.TextBox3.Value = "Contract Number" Me.TextBox4.Value = "Client" Me.TextBox5.Value = "Position" Me.TextBox6.Value = "Start Date" Me.TextBox7.Value = "End Date" Me.TextBox8.Value = "Hours of Work" Me.TextBox9.Value = "Hourly Rate" Me.TextBox10.Value = "Account Manager" Me.CommandButton1.Caption = "OK" Me.CommandButton2.Caption = "Cancel" End Sub Private Sub Commandbutton1_Click() Set oVars = ActiveDocument.Variables Me.Hide oVars("var1").Value = Me.TextBox1.Value oVars("var2").Value = Me.TextBox2.Value oVars("var3").Value = Me.TextBox3.Value oVars("var4").Value = Me.TextBox4.Value oVars("var5").Value = Me.TextBox5.Value oVars("var6").Value = Me.TextBox6.Value oVars("var7").Value = Me.TextBox7.Value oVars("var8").Value = Me.TextBox8.Value oVars("var9").Value = Me.TextBox9.Value oVars("var10").Value = Me.TextBox10.Value ActiveDocument.Fields.Update Set oVars = Nothing Unload Me End Sub Private Sub Commandbutton2_Click() Unload Me End Sub Code:
Option Explicit Sub ShowMyForm() UserForm1.Show End Sub Sub AutoNew() ShowMyForm End Sub Last edited by macropod; 09-29-2013 at 09:16 PM. Reason: Added code tags |
#2
|
||||
|
||||
![]()
Hi vbanovice,
It would be helpful if you provided something more descriptive than: Quote:
Quote:
A sample document with the form and code would also make diagnosis easier. You can attach a document to a post (delete anything sensitive) via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to use the SaveAsDialog after UserForm is closed | drod | Word VBA | 0 | 03-03-2013 08:06 PM |
Question on userform and doc interaction | icecode | Word | 3 | 08-01-2012 08:41 AM |
showing a userform after hiding | jillapass | Word VBA | 0 | 05-31-2012 06:13 AM |
VBA code to update record in Access 2003 using Userform in Excel | primmer3001 | Excel Programming | 0 | 08-29-2011 04:25 PM |
Outlook userform validation help | aiwnjoo | Outlook | 0 | 12-08-2010 12:57 AM |