D
DeputySmith770
I have a form which on open a UserForm promts the user to input common
case data. After clicking the UserForm closed, the data filled into
the UserForm creates custom document properties, and populates the
Word Form at pre-defined bookmark locations.
The issue is that if the user incorrectly entered data into the
UserForm, or missed something all together, they can't change it as
the code is written now. Can someone help me figure out how to re-
open the UserForm containing the current values of the Custom Doc
Proeprties, allow the user to change the values, and then re-populate
the Word Form with the new values?
Here is the code I am working with now:
*************************************
Private Sub CommandButton1_Click()
'Check what type of protection - if any - has been applied
Select Case ActiveDocument.ProtectionType
'This tells the program the protection type is set to allow changes to
formfields only.
Case wdAllowOnlyFormFields
'If we've got this far, it's protected for forms
'Now unprotect the document
ActiveDocument.Unprotect Password:="28990"
ActiveDocument.SpellingChecked = False
'Dim CaseNumber As String
'Dim IncidentType As String
With ActiveDocument.CustomDocumentProperties
.Add Name:="Case Number", LinkToContent:=False,
Value:=CaseNumber, Type:=msoPropertyTypeString
.Add Name:="Incident Type", LinkToContent:=False,
Value:=IncidentType, Type:=msoPropertyTypeString
.Add Name:="Report Date", LinkToContent:=False,
Value:=ReportDate, Type:=msoPropertyTypeString
.Add Name:="Report Time", LinkToContent:=False,
Value:=ReportTime, Type:=msoPropertyTypeString
.Add Name:="Occurred Date1", LinkToContent:=False,
Value:=OccurredDate1, Type:=msoPropertyTypeString
.Add Name:="Occurred Date2", LinkToContent:=False,
Value:=OccurredDate2, Type:=msoPropertyTypeString
.Add Name:="Occurred Time1", LinkToContent:=False,
Value:=OccurredTime1, Type:=msoPropertyTypeString
.Add Name:="Occurred Time2", LinkToContent:=False,
Value:=OccurredTime2, Type:=msoPropertyTypeString
.Add Name:="Deputy Name", LinkToContent:=False,
Value:=DeputyName, Type:=msoPropertyTypeString
.Add Name:="Deputy Radio", LinkToContent:=False,
Value:=DeputyRadio, Type:=msoPropertyTypeString
.Add Name:="Deputy DPSST", LinkToContent:=False,
Value:=DeputyDPSST, Type:=msoPropertyTypeString
End With
'This ends the selected section of the protected document.
End Select
ActiveDocument.Fields.Update
ActiveDocument.Repaginate
'Re-protect the document, and apply the same password protection.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="28990"
Application.ScreenUpdating = True
Application.ScreenRefresh
OpenInfo.Hide
End Sub
***************************************
Thanks!
case data. After clicking the UserForm closed, the data filled into
the UserForm creates custom document properties, and populates the
Word Form at pre-defined bookmark locations.
The issue is that if the user incorrectly entered data into the
UserForm, or missed something all together, they can't change it as
the code is written now. Can someone help me figure out how to re-
open the UserForm containing the current values of the Custom Doc
Proeprties, allow the user to change the values, and then re-populate
the Word Form with the new values?
Here is the code I am working with now:
*************************************
Private Sub CommandButton1_Click()
'Check what type of protection - if any - has been applied
Select Case ActiveDocument.ProtectionType
'This tells the program the protection type is set to allow changes to
formfields only.
Case wdAllowOnlyFormFields
'If we've got this far, it's protected for forms
'Now unprotect the document
ActiveDocument.Unprotect Password:="28990"
ActiveDocument.SpellingChecked = False
'Dim CaseNumber As String
'Dim IncidentType As String
With ActiveDocument.CustomDocumentProperties
.Add Name:="Case Number", LinkToContent:=False,
Value:=CaseNumber, Type:=msoPropertyTypeString
.Add Name:="Incident Type", LinkToContent:=False,
Value:=IncidentType, Type:=msoPropertyTypeString
.Add Name:="Report Date", LinkToContent:=False,
Value:=ReportDate, Type:=msoPropertyTypeString
.Add Name:="Report Time", LinkToContent:=False,
Value:=ReportTime, Type:=msoPropertyTypeString
.Add Name:="Occurred Date1", LinkToContent:=False,
Value:=OccurredDate1, Type:=msoPropertyTypeString
.Add Name:="Occurred Date2", LinkToContent:=False,
Value:=OccurredDate2, Type:=msoPropertyTypeString
.Add Name:="Occurred Time1", LinkToContent:=False,
Value:=OccurredTime1, Type:=msoPropertyTypeString
.Add Name:="Occurred Time2", LinkToContent:=False,
Value:=OccurredTime2, Type:=msoPropertyTypeString
.Add Name:="Deputy Name", LinkToContent:=False,
Value:=DeputyName, Type:=msoPropertyTypeString
.Add Name:="Deputy Radio", LinkToContent:=False,
Value:=DeputyRadio, Type:=msoPropertyTypeString
.Add Name:="Deputy DPSST", LinkToContent:=False,
Value:=DeputyDPSST, Type:=msoPropertyTypeString
End With
'This ends the selected section of the protected document.
End Select
ActiveDocument.Fields.Update
ActiveDocument.Repaginate
'Re-protect the document, and apply the same password protection.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="28990"
Application.ScreenUpdating = True
Application.ScreenRefresh
OpenInfo.Hide
End Sub
***************************************
Thanks!