Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-18-2013, 06:44 PM
vbanovice vbanovice is offline Userform Code not quite right - help please Windows 7 64bit Userform Code not quite right - help please Office 2010 64bit
Novice
Userform Code not quite right - help please
 
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
 

Thread Tools
Display Modes


Similar Threads
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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft