J
Jill D
I know I already asked this question but I wasn't able to post the code until
now.
I have been trying to make a template for my company (vet hospital) for our
surgery dismissals. I'm totally new to this and have been having many many
problems. After finally figuring out how to do the userform I tested it. When
I hit the OK or Cancel buttons the template disappears and Word goes into a
regular blank document. Here's the code for the userform and the OK and
Cancel buttons.
This is for the Userform:
Private Sub Document_New()
Dim oForm As frmDismissal
On Error Goto Error_DocumentNew
Set oForm = New frmDismissal
oForm.Tag = "Cancel"
oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy")
oForm.Show
If oForm.Tag = "OK" Then
ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text
ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text
ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text
ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text
Unload oForm
Set oForm = Nothing
Else
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
End If
Exit_DocumentNew:
Exit Sub
Error_DocumentNew:
On Error Resume Next
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
Resume Exit_DocumentNew
End Sub
Here's the next one (for the cancel button):
Option Explicit
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Here's the ok button:
Private Sub cmdOK_Click()
Me.Tag = "OK"
Me.Hide
End Sub
Just one last thing....is there a way for me to have the bookmark be a
certain name (i.e. ClientName) instead of just a blank space with the
bookmark icon?
Thanks for all your help!!
Jill
now.
I have been trying to make a template for my company (vet hospital) for our
surgery dismissals. I'm totally new to this and have been having many many
problems. After finally figuring out how to do the userform I tested it. When
I hit the OK or Cancel buttons the template disappears and Word goes into a
regular blank document. Here's the code for the userform and the OK and
Cancel buttons.
This is for the Userform:
Private Sub Document_New()
Dim oForm As frmDismissal
On Error Goto Error_DocumentNew
Set oForm = New frmDismissal
oForm.Tag = "Cancel"
oForm.txtDate.Text = Format$(Date, "mm/dd/yyyy")
oForm.Show
If oForm.Tag = "OK" Then
ActiveDocument.Bookmarks("ClientName").Range.Text = oForm.txtClientName.Text
ActiveDocument.Bookmarks("PetName").Range.Text = oForm.txtPetName.Text
ActiveDocument.Bookmarks("Doctor").Range.Text = oForm.txtDoctor.Text
ActiveDocument.Bookmarks("Date").Range.Text = oForm.txtDate.Text
Unload oForm
Set oForm = Nothing
Else
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
End If
Exit_DocumentNew:
Exit Sub
Error_DocumentNew:
On Error Resume Next
Unload oForm
Set oForm = Nothing
ActiveDocument.Close wdDoNotSaveChanges
Resume Exit_DocumentNew
End Sub
Here's the next one (for the cancel button):
Option Explicit
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Here's the ok button:
Private Sub cmdOK_Click()
Me.Tag = "OK"
Me.Hide
End Sub
Just one last thing....is there a way for me to have the bookmark be a
certain name (i.e. ClientName) instead of just a blank space with the
bookmark icon?
Thanks for all your help!!
Jill