none
How do I clear data fields in UserForm created with vba - Msword 2007 RRS feed

  • Question

  • I have a word 2007 document that uses userform created in vba.  The form works fine except, everytime a new case is opened, the previous data is in the fields.  Each use of the form, adds data to the field.  I can't seem to use Userform.Unload in 2007 (unless I am not using it correctly) because I get an error message each time (Compile error:  Method or data member not found).  Below is the code I am using.  Appreciate your help - Thanks.

    Private Sub ComboBox1_Change()
    End Sub


    Private Sub CommandButton1_Click()
    With ActiveDocument
    .Bookmarks("Casual").Range _
    .InsertBefore (TextBox1)
    .Bookmarks("Bias").Range _
    .InsertBefore (TextBox2)
    .Bookmarks("Double").Range _
    .InsertBefore (TextBox3)
    .Bookmarks("Unclear").Range _
    .InsertBefore (TextBox4)
    .Bookmarks("Perfection").Range _
    .InsertBefore (TextBox5)
    .Bookmarks("Sure").Range _
    .InsertBefore (TextBox6)
    .Bookmarks("Unsure").Range _
    .InsertBefore (TextBox7)
    .Bookmarks("Value").Range _
    .InsertBefore (TextBox8)
    .Bookmarks("Rally").Range _
    .InsertBefore (TextBox9)
    .Bookmarks("Number").Range _
    .InsertBefore (TextBox10)
    .Bookmarks("Negative").Range _
    .InsertBefore (TextBox11)
    End With
    UserForm.Hide
    End Sub

    Private Sub CommandButton2_Click()
    Me.Hide
    End Sub

    Private Sub Label5_Click()
    End Sub


    Private Sub UserForm_Click()
    'Run the form
    With ActiveDocument
    .Bookmarks("Casual").Range _
    .InsertBefore (TextBox1)
    .Bookmarks("Bias").Range _
    .InsertBefore (TextBox2)
    .Bookmarks("Double").Range _
    .InsertBefore (TextBox3)
    .Bookmarks("Unclear").Range _
    .InsertBefore (TextBox4)
    .Bookmarks("Perfection").Range _
    .InsertBefore (TextBox5)
    .Bookmarks("Sure").Range _
    .InsertBefore (TextBox6)
    .Bookmarks("Unsure").Range _
    .InsertBefore (TextBox7)
    .Bookmarks("Value").Range _
    .InsertBefore (TextBox8)
    .Bookmarks("Rally").Range _
    .InsertBefore (TextBox9)
    .Bookmarks("Number").Range _
    .InsertBefore (TextBox10)
    .Bookmarks("Negative").Range _
    .InsertBefore (TextBox11)
    End With
    UserForm.Show
    End Sub

    Tuesday, January 8, 2013 7:43 PM

Answers