Word Template Problem - Worked in 2003, not in 2007

L

LC

I have a template that worked fine in Word 2003, but doesn't in Word 2007.

The template (either the original .dot or the converted .dotm) was created
by me and has userforms and VBA code with a couple of buttons on the form
that users click on. The form is stored in a network folder. The template
is used as a paperless form that several people open, modify, and close
before the process is finally complete. A command button is clicked each
time and a form allows the user to select a radio button to note which step
they completed, which then triggers VBA code to run.

Here's how it works:
The first person runs the template which creates a new document. They put
in their information and click the command button. The code does a "Save As"
and saves the document with a date-stamped name in a folder on the network
and generates an email to a mail group. The next person opens a link to the
document in their email and adds their part to the document and clicks the
command button. The code does a "Save" to the same document, incorporating
the changes and generates an email to the next group. The next group does
their thing and clicking the command button just does a final "Save" and
that's how it works in Word 2003.

In 2007, after the first person clicks the command button and it does a
"Save As" the email generated has the correct link and can be opened.
However, when looking at the References in VBA, it shows a missing link to a
randomly named file with .dotm extension (e.g. MISSING: 2066F1DD.dotm). When
the user does their part and clicks the command button, it doesn't error, but
the email link sent in the email points to a missing file in the temporary
internet files (e.g. C:\Documents and Settings\<username>\Local
Settings\Temporary Internet Files\Content.MSO\CCA774F2.doc). I put MsgBoxs
into the VBA code to show the Err.Number and Err.Description and I get Error
5355 "The save failed due to out of memory or disk space.", which is
definitely not the case.

I've tried modifying the code to save the new document created by the
template as .docm and it won't even open for the next person. Simply
removing the "m" on the end will allow it to open though.

I'm at a loss as to what is going on. I don't know why things are being
saved in the temporary internet files and not the network folder. I have
verified that the users and I all have Modify rights to the directory and
this works perfectly with Word 2003.

Thanks for any help!
 
D

Doug Robbins - Word MVP

Does the original Word 2003 template work in Word 2007? If it does, there
is really no reason to convert it to a Word 2007 template.

Other than that, without seeing the code, it is hard to give any other
hints.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

LC

Yes it does work. I converted it because I thought that may be the problem,
but it didn't help. I even recreated it in 2007, using the same code, and it
did the same thing.

I have code for the document itself, code for each form (4 of them) and code
for a module. Do you want to see the code for the saving/emailing form or
all code?

Thanks!
 
D

Doug Robbins - Word MVP

If it ain't broke, don't fix it.

However, I guess the following is not quite what you meant to say:

"Yes it does work. I converted it because I thought that may be the
problem,
but it didn't help."

It would be best to show all of the code.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

LC

Correct. I meant to say it doesn't work in 2007, but does work in 2003. So
here's the code. Sorry, it is quite a bit. This is also my first big effort
in doing VBA, so the coding may not be ideal. I put a line of slashes
(/////) to separate code between objects. The post was too long, so I have
separated it into 2 posts.

///////////////////////////////////////////////////////////
'Microsoft Word Objects: Code for “ThisDocumentâ€
Private Sub Document_New()
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
With Application
.WindowState = wdWindowStateMinimize
End With
If FormData.AccTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.AccTextBox.SetFocus
FormData.Show
ElseIf FormData.PACSTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.Show
FormData.PACSTextBox.SetFocus
ElseIf FormData.DirTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.DirTextBox.SetFocus
FormData.Show
End If
InfoForm.Show
End Sub

Private Sub Document_Open()
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
Application.WindowState = wdWindowStateMaximize
If FormData.AccTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.AccTextBox.SetFocus
FormData.Show
ElseIf FormData.PACSTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.Show
FormData.PACSTextBox.SetFocus
ElseIf FormData.DirTextBox.Value = "" Then
MsgBox "You must fill out the necessary form data information.",
vbOKOnly + vbInformation, "Missing form data"
FormData.DirTextBox.SetFocus
FormData.Show
End If
End Sub

Private Sub Document_Close()
ActiveDocument.Saved = True
Application.DisplayAlerts = wdAlertsNone
End Sub

Private Sub FinishedBtn_Click()
CloseForm.Show
End Sub

Private Sub ManageFormBtn_Click()
FormData.Show
End Sub

Private Sub Application_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub


///////////////////////////////////////////////////////////
‘Forms: Code for “CloseFormâ€
Private Sub SelectionBtn_Click()
On Error Resume Next
Dim blnEmailClient As Boolean
Dim strFileName, strDateTime, strDirPath, strHour, strMinute

If Hour(Now) < 10 Then
strHour = "0" & Hour(Now)
Else
strHour = Hour(Now)
End If
If Minute(Now) < 10 Then
strMinute = "0" & Minute(Now)
Else
strMinute = Minute(Now)
End If
strDateTime = Month(Now) & "." & Day(Now) & "." & Year(Now) & "_" &
strHour & "." & strMinute
strFileName = "OSF_" & strDateTime & ".doc"
If Not Right(strDir, 1) = "\" Then
strDirPath = FormData.DirTextBox.Value & "\"
Else
strDirPath = FormData.DirTextBox.Value
End If
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDir) Then
MsgBox "The folder set to save this document is missing." & vbCrLf _
& vbCrLf & "Please correct the location by clicking the Manage Form
Data button.", vbOKOnly + vbExclamation, "Missing Folder!"
Unload Me
Exit Sub
End If
blnEmailClient = False
strOutlookPath = "C:\Program Files\Microsoft Office\OFFICE12\Outlook.exe"
If objFSO.FileExists(strOutlookPath) Then
blnEmailClient = True
End If

If PatientStudyDoneBtn.Value = True Then
ActiveDocument.SaveAs (strDirPath & strFileName)
If blnEmailClient = True Then
Call Create_OL_Mail(FormData.AccTextBox.Value, _
"OSF - Ready for ACC numbers - " & ActiveDocument.Name, _
"<html><head></head><body>Click here to open the document:
<a href='file:///" & ActiveDocument.Path & "\" & ActiveDocument.Name & "'
title=" & strFileName & ">" & ActiveDocument.Name & "</a></body></html>")
Else
Call SendEmail("<fromaddress>", FormData.AccTextBox.Value, _
"OSF - Ready for ACC numbers - " & ActiveDocument.Name, _
"<html><head></head><body>Click here to open the document:
<a href='file:///" & ActiveDocument.Path & "\" & ActiveDocument.Name & "'
title=" & strFileName & ">" & ActiveDocument.Name & "</a></body></html>")
End If
Unload Me
If Word.Documents.Count = 1 Then
Word.Application.Quit (wdDoNotSaveChanges)
Else
ActiveDocument.Close (wdDoNotSaveChanges)
End If
ElseIf AccDoneBtn.Value = True Then
If Left(ActiveDocument.Name, 8) = "Document" Then
ActiveDocument.SaveAs (strDirPath & strFileName)
Else
ActiveDocument.Saved = False
ActiveDocument.Save
End If
If blnEmailClient = True Then
Call Create_OL_Mail(FormData.PACSTextBox.Value, _
"OSF - Ready for VI/iSite - " & ActiveDocument.Name, _
"<html><head></head><body>Click here to open the document:
<a href='file:///" & ActiveDocument.Path & "\" & ActiveDocument.Name & "'
title=" & strFileName & ">" & ActiveDocument.Name & "</a></body></html>")
Else
Call SendEmail("<fromaddress>", FormData.PACSTextBox.Value, _
"OSF - Ready for VI/iSite - " & ActiveDocument.Name, _
"<html><head></head><body>Click here to open the document:
<a href='file:///" & ActiveDocument.Path & "\" & ActiveDocument.Name & "'
title=" & strFileName & ">" & ActiveDocument.Name & "</a></body></html>")
End If
Unload Me
If Word.Documents.Count = 1 Then
Word.Application.Quit (wdDoNotSaveChanges)
Else
ActiveDocument.Close (wdDoNotSaveChanges)
End If
ElseIf PACSDoneBtn.Value = True Then
ActiveDocument.Save
Unload Me
If Word.Documents.Count = 1 Then
Word.Application.Quit (wdDoNotSaveChanges)
Else
ActiveDocument.Close (wdDoNotSaveChanges)
End If
ElseIf CloseNoChangesBtn.Value = True Then
Unload Me
ActiveDocument.Saved = True
Application.DisplayAlerts = wdAlertsNone
Word.Application.Quit (wdDoNotSaveChanges)
End If
Set objFSO = Nothing
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub

Public Sub Create_OL_Mail(strMailTo, strSubject, strMessage)
On Error Resume Next
Dim olApp As Outlook.Application
Dim olMailItm As Outlook.MailItem

Set olApp = New Outlook.Application
' Create new OL mail item.
Set olMailItm = olApp.CreateItem(olMailItem)

With olMailItm
..BodyFormat = olFormatHTML
..To = strMailTo
..Subject = strSubject
..HTMLBody = strMessage
..Send 'Display or Send
'.Save
'.Close False
End With

'olApp.Quit
Set olApp = Nothing
Set olMailItm = Nothing
End Sub

Public Function SendEmail(strMailFrom, strMailTo, strSubject, strMessage)
On Error Resume Next
Const cdoSendUsingMethod =
"http://schemas.microsoft.com/cdo/configuration/sendusing", _
cdoSendUsingPort = 2, _
cdoSMTPServer =
"http://schemas.microsoft.com/cdo/configuration/smtpserver"

Dim iMsg, iConf, Flds

' Create the CDO connections.
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "<smtpmailserver>"
.Update
End With
' Set the message properties.
With iMsg
Set .Configuration = iConf
.To = strMailTo
.From = strMailFrom
.Subject = strSubject
.TextBody = strMessage
End With
iMsg.HTMLBody = strMessage
On Error Resume Next
iMsg.Send ' send the message.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Function
Private Sub CancelBtn_Click()
Unload Me
End Sub
 

///////////////////////////////////////////////////////////
‘Forms: Code for “FormDataâ€
Private Sub CancelBtn_Click()
Unload Me
End Sub

Private Sub FinishedBtn_Click()
On Error Resume Next
Dim quote
quote = Chr(34)
Set CodeMod = ThisDocument.VBProject.VBComponents("Module1").CodeModule
With CodeMod
.ReplaceLine 1, "Public Const strDir = " & quote & DirTextBox.Value
& quote
.ReplaceLine 2, "Public Const strAccEmail = " & quote &
AccTextBox.Value & quote
.ReplaceLine 3, "Public Const strPACSEmail = " & quote &
PACSTextBox.Value & quote
End With
Templates(1).Save
Me.Hide
End Sub

Private Sub UserForm_Initialize()
AccTextBox.Value = strAccEmail
PACSTextBox.Value = strPACSEmail
DirTextBox.Value = strDir
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub


///////////////////////////////////////////////////////////
‘Forms: Code for “InfoFormâ€
Private Sub CancelBtn_Click()
Unload Me
Word.Application.Quit (wdDoNotSaveChanges)
End Sub

Private Sub ConsultNoBtn_Click()
ConsultTextBox.Value = ""
ConsultTextBox.Enabled = False
End Sub

Private Sub ConsultYesBtn_Click()
ConsultTextBox.Enabled = True
End Sub

Private Sub Cmdclose_Click()
Unload Me
End Sub

Private Sub ManageFormBtn_Click()
FormData.Show
End Sub

Private Sub UserForm_Initialize()
InfoForm.MedicalFacilityComboBox.List() = Array("Hospital 1", " Hospital
2", _
" Hospital 3", " Hospital 4", " Hospital 5", " Hospital 6", _
" Hospital 7", " Hospital 8", " Hospital 9")

With InfoForm.MonthComboBox
For i = 1 To 12
.AddItem i
Next i
End With
With InfoForm.DayComboBox
For i = 1 To 31
.AddItem i
Next i
End With
With InfoForm.YearComboBox
For i = Year(Now) - 105 To Year(Now) - 16
.AddItem i
Next i
End With
InfoForm.MonthComboBox.Value = Month(Now)
InfoForm.DayComboBox.Value = Day(Now)
InfoForm.YearComboBox.Value = Year(Now) - 60
InfoForm.ConsultTextBox.Enabled = False
End Sub

Private Sub FinishBtn_Click()
If NameTextBox.Value = "" Then
MsgBox "Please enter a patient name.", vbExclamation, "Error!"
InfoForm.NameTextBox.SetFocus
Exit Sub
ElseIf SSNTextBox1.Value = "" Then
MsgBox "Please enter a SSN.", vbExclamation, "Error!"
InfoForm.SSNTextBox1.SetFocus
Exit Sub
ElseIf SSNTextBox1.TextLength < 3 Then
MsgBox "Less than the required number of digits was entered for the
SSN. Please retry." _
, vbOKOnly + vbExlamation, "Error!"
InfoForm.SSNTextBox1.SetFocus
Exit Sub
ElseIf SSNTextBox2.TextLength < 2 Then
MsgBox "Less than the required number of digits was entered for the
SSN. Please retry." _
, vbOKOnly + vbExlamation, "Error!"
InfoForm.SSNTextBox2.SetFocus
Exit Sub
ElseIf SSNTextBox3.TextLength < 4 Then
MsgBox "Less than the required number of digits was entered for the
SSN. Please retry." _
, vbOKOnly + vbExlamation, "Error!"
InfoForm.SSNTextBox3.SetFocus
Exit Sub
ElseIf SSNTextBox2.Value = "" Then
MsgBox "Please enter a SSN.", vbExclamation, "Error!"
InfoForm.SSNTextBox2.SetFocus
Exit Sub
ElseIf SSNTextBox3.Value = "" Then
MsgBox "Please enter a SSN.", vbExclamation, "Error!"
InfoForm.SSNTextBox3.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter a date of birth.", vbExclamation, "Error!"
InfoForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter a date of birth.", vbExclamation, "Error!"
InfoForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter a date of birth.", vbExclamation, "Error!"
InfoForm.YearComboBox.SetFocus
Exit Sub
ElseIf MedicalFacilityComboBox.Value = "" Then
MsgBox "Please enter a medical facility.", vbExclamation, "Error!"
InfoForm.MedicalFacilityComboBox.SetFocus
Exit Sub
ElseIf ConsultYesBtn.Value = True Then
If ConsultTextBox.Value = "" Then
MsgBox "Please enter a requestor.", vbExclamation, "Error!"
InfoForm.ConsultTextBox.SetFocus
Exit Sub
End If
ElseIf SourceTextBox.Value = "" Then
MsgBox "Please enter a source.", vbExclamation, "Error!"
InfoForm.SourceTextBox.SetFocus
Exit Sub
End If

ActiveDocument.Bookmarks("Name").Range.Text = NameTextBox.Value
ActiveDocument.Bookmarks("SSN").Range.Text = SSNTextBox1.Value & "-" &
SSNTextBox2.Value & "-" & SSNTextBox3.Value
ActiveDocument.Bookmarks("DOB").Range.Text = MonthComboBox.Value & "/" &
DayComboBox.Value & "/" & YearComboBox.Value
ActiveDocument.Bookmarks("Facility").Range.Text =
MedicalFacilityComboBox.Value
If ConsultNoBtn.Value = True Then
ActiveDocument.Bookmarks("ConsultRequest").Range.Text = "No"
ActiveDocument.Bookmarks("ConsultRequestor").Range.Text = ""
Else
ActiveDocument.Bookmarks("ConsultRequest").Range.Text = "Yes"
ActiveDocument.Bookmarks("ConsultRequestor").Range.Text =
ConsultTextBox.Value
End If
ActiveDocument.Bookmarks("Source").Range.Text = SourceTextBox.Value
InfoForm.Hide
StudyForm.Show
Exit Sub
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub

Private Sub SSNTextBox1_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With SSNTextBox1
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub SSNTextBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With SSNTextBox1
LastPosition = .SelStart
End With
End Sub

Private Sub SSNTextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With SSNTextBox1
LastPosition = .SelStart
End With
End Sub

Private Sub SSNTextBox2_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With SSNTextBox2
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub SSNTextBox2_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With SSNTextBox1
LastPosition = .SelStart
End With
End Sub

Private Sub SSNTextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With SSNTextBox2
LastPosition = .SelStart
End With
End Sub

Private Sub SSNTextBox3_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With SSNTextBox3
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub SSNTextBox3_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With SSNTextBox3
LastPosition = .SelStart
End With
End Sub

Private Sub SSNTextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With SSNTextBox3
LastPosition = .SelStart
End With
End Sub

Private Sub MonthComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MonthComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MonthComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MonthComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With DayComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub DayComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With YearComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub YearComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With YearComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With YearComboBox
LastPosition = .SelStart
End With
End Sub
 
L

LC

Part 2

///////////////////////////////////////////////////////////
‘Forms: Code for “StudyFormâ€
Private Sub SubmitAddBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation, "Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value & "
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold = False
ActiveDocument.Bookmarks("Report" & i).Range.Text = "No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold = True
ActiveDocument.Bookmarks("Report" & i).Range.Text = "YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
StudyForm.Hide
ModalityTextBox.Value = Null
ExamTextBox.Value = Null
MonthComboBox.Value = Month(Now)
DayComboBox.Value = Day(Now)
YearComboBox.Value = Year(Now)
ReportNoBtn.Value = True
ImagesTextBox.Value = Null
HourComboBox.Value = Hour(Now)
MinuteComboBox.Value = Minute(Now)
StudyForm.ModalityTextBox.SetFocus
StudyForm.Show
Exit Sub
End If
End If
Next i
End Sub

Private Sub UserForm_Initialize()
Dim i
With StudyForm.MonthComboBox
For i = 1 To 12
.AddItem i
Next i
End With
With StudyForm.DayComboBox
For i = 1 To 31
.AddItem i
Next i
End With
With StudyForm.YearComboBox
For i = 1980 To Year(Now)
.AddItem i
Next i
End With
With StudyForm.HourComboBox
For i = 0 To 23
.AddItem i
Next i
End With
With StudyForm.MinuteComboBox
For i = 0 To 59
.AddItem i
Next i
End With
StudyForm.MonthComboBox.Value = Month(Now)
StudyForm.DayComboBox.Value = Day(Now)
StudyForm.YearComboBox.Value = Year(Now)
StudyForm.HourComboBox.Value = Hour(Now)
StudyForm.MinuteComboBox.Value = Minute(Now)
End Sub

Private Sub SubmitBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation, "Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
If MonthComboBox.TextLength < 2 Then
MonthComboBox.Value = "0" & MonthComboBox.Value
End If
If DayComboBox.TextLength < 2 Then
DayComboBox.Value = "0" & DayComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value & "
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold = False
ActiveDocument.Bookmarks("Report" & i).Range.Text = "No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold = True
ActiveDocument.Bookmarks("Report" & i).Range.Text = "YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
Unload Me
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
With Application
.WindowState = wdWindowStateMaximize
End With
Exit Sub
End If
End If
Next i
End Sub

Private Sub CancelBtn_Click()
Unload Me
With Application
.WindowState = wdWindowStateMaximize
End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub

Private Sub MonthComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MonthComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MonthComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MonthComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With DayComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub DayComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With YearComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub YearComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With YearComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With YearComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub HourComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With HourComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub HourComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With HourComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub HourComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With HourComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MinuteComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MinuteComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MinuteComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MinuteComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MinuteComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With MinuteComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub ImagesTextBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With ImagesTextBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
..Text = LastText
..SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub ImagesTextBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With ImagesTextBox
LastPosition = .SelStart
End With
End Sub

Private Sub ImagesTextBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With ImagesTextBox
LastPosition = .SelStart
End With
End Sub

 
///////////////////////////////////////////////////////////
‘Modules: Code for “Module1â€
Public Const strDir = “<pathtosavenewdocument"
Public Const strAccEmail = "<emailaddress1>"
Public Const strPACSEmail = "<emailaddress2>"
 
D

Doug Robbins - Word MVP

Can you send me a copy of the template and I will have a look at the
problem.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
LC said:
Part 2

///////////////////////////////////////////////////////////
‘Forms: Code for “StudyFormâ€
Private Sub SubmitAddBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation,
"Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value &
"
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
False
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
True
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
StudyForm.Hide
ModalityTextBox.Value = Null
ExamTextBox.Value = Null
MonthComboBox.Value = Month(Now)
DayComboBox.Value = Day(Now)
YearComboBox.Value = Year(Now)
ReportNoBtn.Value = True
ImagesTextBox.Value = Null
HourComboBox.Value = Hour(Now)
MinuteComboBox.Value = Minute(Now)
StudyForm.ModalityTextBox.SetFocus
StudyForm.Show
Exit Sub
End If
End If
Next i
End Sub

Private Sub UserForm_Initialize()
Dim i
With StudyForm.MonthComboBox
For i = 1 To 12
.AddItem i
Next i
End With
With StudyForm.DayComboBox
For i = 1 To 31
.AddItem i
Next i
End With
With StudyForm.YearComboBox
For i = 1980 To Year(Now)
.AddItem i
Next i
End With
With StudyForm.HourComboBox
For i = 0 To 23
.AddItem i
Next i
End With
With StudyForm.MinuteComboBox
For i = 0 To 59
.AddItem i
Next i
End With
StudyForm.MonthComboBox.Value = Month(Now)
StudyForm.DayComboBox.Value = Day(Now)
StudyForm.YearComboBox.Value = Year(Now)
StudyForm.HourComboBox.Value = Hour(Now)
StudyForm.MinuteComboBox.Value = Minute(Now)
End Sub

Private Sub SubmitBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation,
"Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
If MonthComboBox.TextLength < 2 Then
MonthComboBox.Value = "0" & MonthComboBox.Value
End If
If DayComboBox.TextLength < 2 Then
DayComboBox.Value = "0" & DayComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value &
"
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
False
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
True
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
Unload Me
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
With Application
.WindowState = wdWindowStateMaximize
End With
Exit Sub
End If
End If
Next i
End Sub

Private Sub CancelBtn_Click()
Unload Me
With Application
.WindowState = wdWindowStateMaximize
End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub

Private Sub MonthComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MonthComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MonthComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MonthComboBox_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With DayComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub DayComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With DayComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With YearComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub YearComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With YearComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub YearComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With YearComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub HourComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With HourComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub HourComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With HourComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub HourComboBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With HourComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MinuteComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MinuteComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MinuteComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MinuteComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MinuteComboBox_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With MinuteComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub ImagesTextBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With ImagesTextBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub ImagesTextBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With ImagesTextBox
LastPosition = .SelStart
End With
End Sub

Private Sub ImagesTextBox_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With ImagesTextBox
LastPosition = .SelStart
End With
End Sub


///////////////////////////////////////////////////////////
‘Modules: Code for “Module1â€
Public Const strDir = “<pathtosavenewdocument"
Public Const strAccEmail = "<emailaddress1>"
Public Const strPACSEmail = "<emailaddress2>"
 
L

LC

Yes, I'll be sending it in just a minute.

Also, in using it this morning, I have discovered that if the initial step
is done on Word 2003, the template reference is correct and points to the
template stored in the network folder. This step is where a user
double-clicks on the template and it creates a new document based on the
template and then the code does a "Save As" with a time-stamped name.

However, if that same step is done on Word 2007, the reference is pointing
to a file in the temporary internet files instead of the correct template in
the network folder. Hopefully that will help narrow down the problem.

Doug Robbins - Word MVP said:
Can you send me a copy of the template and I will have a look at the
problem.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
LC said:
Part 2

///////////////////////////////////////////////////////////
‘Forms: Code for “StudyFormâ€
Private Sub SubmitAddBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation,
"Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value &
"
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
False
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
True
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
StudyForm.Hide
ModalityTextBox.Value = Null
ExamTextBox.Value = Null
MonthComboBox.Value = Month(Now)
DayComboBox.Value = Day(Now)
YearComboBox.Value = Year(Now)
ReportNoBtn.Value = True
ImagesTextBox.Value = Null
HourComboBox.Value = Hour(Now)
MinuteComboBox.Value = Minute(Now)
StudyForm.ModalityTextBox.SetFocus
StudyForm.Show
Exit Sub
End If
End If
Next i
End Sub

Private Sub UserForm_Initialize()
Dim i
With StudyForm.MonthComboBox
For i = 1 To 12
.AddItem i
Next i
End With
With StudyForm.DayComboBox
For i = 1 To 31
.AddItem i
Next i
End With
With StudyForm.YearComboBox
For i = 1980 To Year(Now)
.AddItem i
Next i
End With
With StudyForm.HourComboBox
For i = 0 To 23
.AddItem i
Next i
End With
With StudyForm.MinuteComboBox
For i = 0 To 59
.AddItem i
Next i
End With
StudyForm.MonthComboBox.Value = Month(Now)
StudyForm.DayComboBox.Value = Day(Now)
StudyForm.YearComboBox.Value = Year(Now)
StudyForm.HourComboBox.Value = Hour(Now)
StudyForm.MinuteComboBox.Value = Minute(Now)
End Sub

Private Sub SubmitBtn_Click()
Dim i
If ModalityTextBox.Value = "" Then
MsgBox "Please enter a modality type.", vbExclamation, "Error!"
StudyForm.ModalityTextBox.SetFocus
Exit Sub
ElseIf ExamTextBox.Value = "" Then
MsgBox "Please enter an exam type.", vbExclamation, "Error!"
StudyForm.ExamTextBox.SetFocus
Exit Sub
ElseIf MonthComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.MonthComboBox.SetFocus
Exit Sub
ElseIf DayComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.DayComboBox.SetFocus
Exit Sub
ElseIf YearComboBox.Value = "" Then
MsgBox "Please enter an exam date.", vbExclamation, "Error!"
StudyForm.YearComboBox.SetFocus
Exit Sub
ElseIf HourComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.HourComboBox.SetFocus
Exit Sub
ElseIf MinuteComboBox.Value = "" Then
MsgBox "Please enter an exam time.", vbExclamation, "Error!"
StudyForm.MinuteComboBox.SetFocus
Exit Sub
ElseIf ImagesTextBox.Value = "" Then
MsgBox "Please enter the number of images.", vbExclamation,
"Error!"
StudyForm.ImagesTextBox.SetFocus
Exit Sub
End If

For i = 1 To 15
If ActiveDocument.Bookmarks.Exists("Type" & i) = True Then
If ActiveDocument.Bookmarks("Type" & i).Range.Text = " " Then
ActiveDocument.Bookmarks("Type" & i).Range.Text =
UCase(ModalityTextBox.Value) & " - " & UCase(ExamTextBox.Value)
If HourComboBox.Value = "" Then
If MonthComboBox.TextLength < 2 Then
MonthComboBox.Value = "0" & MonthComboBox.Value
End If
If DayComboBox.TextLength < 2 Then
DayComboBox.Value = "0" & DayComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value
Else
If HourComboBox.TextLength < 2 Then
HourComboBox.Value = "0" & HourComboBox.Value
End If
If MinuteComboBox.TextLength < 2 Then
MinuteComboBox.Value = "0" & MinuteComboBox.Value
End If
ActiveDocument.Bookmarks("Date" & i).Range.Text =
MonthComboBox.Value & "/" & DayComboBox.Value & "/" & YearComboBox.Value &
"
at " & HourComboBox.Value & ":" & MinuteComboBox.Value
End If
If ReportNoBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorBlack
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
False
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"No"
ElseIf ReportYesBtn.Value = True Then
ActiveDocument.Bookmarks("Report" & i).Range.Font.Color
= wdColorRed
ActiveDocument.Bookmarks("Report" & i).Range.Bold =
True
ActiveDocument.Bookmarks("Report" & i).Range.Text =
"YES"
End If
ActiveDocument.Bookmarks("Images" & i).Range.Text =
ImagesTextBox.Value
Unload Me
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
With Application
.WindowState = wdWindowStateMaximize
End With
Exit Sub
End If
End If
Next i
End Sub

Private Sub CancelBtn_Click()
Unload Me
With Application
.WindowState = wdWindowStateMaximize
End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub

Private Sub MonthComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With MonthComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub

Private Sub MonthComboBox_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub MonthComboBox_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
With MonthComboBox
LastPosition = .SelStart
End With
End Sub

Private Sub DayComboBox_Change()
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With DayComboBox
If .Text Like "*[!0-9]*" Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
 
L

LC

Thank you for looking at the problem and attempting to resolve it Doug!

The problem still exists and Doug unfortunately doesn't have the ability to
test with having the template on a network location. If anyone else can help
resolve this, I would really appreciate it.

I have tested the template with Word 2007 having everything local on the
computer and it works fine. Once you put the template in a network folder,
Word 2007 fails and Word 2003 works. I have tried using both UNC path and
mapped network drives and neither worked in Word 2007.

Please help!
 
J

Jacob Cooper

I have a project that's almost exactly the same in principle, and have
run into the exact same bug. I've found what seems to be an effective
workaround.

In the template, add the following bit of code (from
http://support.microsoft.com/kb/308340)

<code>
Sub CheckMissing()

Dim vbProj As VBProject ' This refers to your VBA project.
Dim chkRef As Reference ' A reference.

' Refer to the activedocument's VBA project.
Set vbProj = ActiveDocument.VBProject

' Check through the selected references in the References dialog
box.
For Each chkRef In vbProj.References

' If the reference is broken, send the name to the Immediate
Window.
If chkRef.IsBroken Then
vbProj.References.Remove chkRef
End If

Next

End Sub
</code>

Call this procedure in the template's Document_Open sub. Every time
the form opens (while connected to the template), it will scan and
remove any missing references.

Hope this helps!

Jacob Cooper
 
J

JAC

I have a project that's almost exactly the same in principle, and have
run into the exact same bug. I've found what seems to be an effective
workaround.

In the template, add the following bit of code (from
http://support.microsoft.com/kb/308340)

<code>
Sub CheckMissing()
Dim vbProj As VBProject ' This refers to your VBA project.
Dim chkRef As Reference ' A reference.
' Refer to the activedocument's VBA project.
Set vbProj = ActiveDocument.VBProject
' Check through the selected references in the References dialog
box.
For Each chkRef In vbProj.References
' If the reference is broken, remove it.
If chkRef.IsBroken Then
vbProj.References.Remove chkRef
End If
Next
End Sub
</code>

Call this procedure in the template's Document_Open sub. Every time
the form opens (while connected to the template), it will scan and
remove any missing references.

Hope this helps!
 
L

LC

Thanks, but that didn't seem to work for me unfortunately. It does remove
the reference, but then none of the code for buttons to bring up forms work.
I tried putting in "Debug.Print chkRef.Name" instead of removing the
reference and the code works, but the problem is still there.

Any other ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top