View Single Post
 
Old 07-18-2013, 06:44 PM
vbanovice vbanovice is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2013
Posts: 1
vbanovice is on a distinguished road
Default Userform Code not quite right - help please

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
Reply With Quote