Calendar control on protected form with multiple date fields

D

Dale

How do a reference the formfield on a protected form to insert a date
from a datepicker? I have 3 date fields, it seems I can insert a date
based on the field selected i.e.
selection.formfields("x")=calendar1.value
Any help is appreciated.
thanks
--
 
D

Dale

Thanks Graham, I actually am using similar code, however my problem is
I have 3 different date fields and I can't figure out how to determine
which field has focus in order to pass the fld("name") to the code
you've shared.
Thanks again
--



Graham Mayor wrote:
See http://www.gmayor.com/popup_calendar.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


How do a reference the formfield on a protected form to insert a
date from a datepicker? I have 3 date fields, it seems I can
insert a date based on the field selected i.e.
selection.formfields("x")=calendar1.value
Any help is appreciated.
thanks
--
 
G

Graham Mayor

Create a Function to get the current formfield name

Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

Run the macro on entry to the date form fields to pop up the calendar/date

Sub Calendar()
frmCalendar.Show
End Sub

Using the code from my web site, make the changes as required

Private Sub Calendar1_Click()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
oFld(GetCurrentFF.name).Result = Format(Calendar1.Value, "dd mmmm yyyy")
Unload Me
End Sub

Private Sub CmdClose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Calendar1.Value = Date 'start with today's date
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dale

Thank you so much Graham, I would never have come up with that and I've
been trying for 2 days!!
--



Graham Mayor wrote:
Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

Run the macro on entry to the date form fields to pop up the
calendar/date

Sub Calendar()
frmCalendar.Show
End Sub

Using the code from my web site, make the changes as required

Private Sub Calendar1_Click()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
oFld(GetCurrentFF.name).Result = Format(Calendar1.Value, "dd mmmm
yyyy") Unload Me
End Sub

Private Sub CmdClose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Calendar1.Value = Date 'start with today's date
End Sub
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dale

Graham,
One last time I hope..this form is going to be the death of me, it
shouldn't have been this difficult! I designed this form in word 2007,
but have since had to redesign in 2000 as we have a wide disparity of
office versions. My newest problem: I'm trying to open a form and I'm
not sure why this form would be any different than the pop up calendar,
but I am now getting an error when using (semail.show) which is an
"email" form, on the protected document.

The error is a runtime error 4605 "method or property is not avaiable
as the object or property it refers to is in a protected area of the
document". The code works in 2007 but it appears 2000 is less
tolerant! Again I don't see how this is any different from opening a
calendar form. Do I have to unprotect the document, open the form run
the email routine behind the form, close the form and then protect the
document, which is not desirable as the saved document would also be
unprotected.

thanks....very close to disabling all macros and going plain jane!!
--



Graham Mayor wrote:
You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Thank you so much Graham, I would never have come up with that and
I've been trying for 2 days!!
--


Graham Mayor wrote:
Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

Run the macro on entry to the date form fields to pop up the
calendar/date

Sub Calendar()
frmCalendar.Show
End Sub

Using the code from my web site, make the changes as required

Private Sub Calendar1_Click()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
oFld(GetCurrentFF.name).Result = Format(Calendar1.Value, "dd mmmm
yyyy") Unload Me
End Sub

Private Sub CmdClose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Calendar1.Value = Date 'start with today's date
End Sub
 
D

Dale

Graham, I did go with unprotecting and protecting the document to open
the email form. It works well, and because my save event happens
before the show.form macro, the saved document is also protected. It
may not be elegant but it works and my life can start again!!
--



Dale wrote:
Graham,
One last time I hope..this form is going to be the death of me, it
shouldn't have been this difficult! I designed this form in word
2007, but have since had to redesign in 2000 as we have a wide
disparity of office versions. My newest problem: I'm trying to open
a form and I'm not sure why this form would be any different than the
pop up calendar, but I am now getting an error when using
(semail.show) which is an "email" form, on the protected document.

The error is a runtime error 4605 "method or property is not avaiable
as the object or property it refers to is in a protected area of the
document". The code works in 2007 but it appears 2000 is less
tolerant! Again I don't see how this is any different from opening a
calendar form. Do I have to unprotect the document, open the form run
the email routine behind the form, close the form and then protect
the document, which is not desirable as the saved document would also
be unprotected.

thanks....very close to disabling all macros and going plain jane!!
--



Graham Mayor wrote:
You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Thank you so much Graham, I would never have come up with that and
I've been trying for 2 days!!
--


Graham Mayor wrote:
Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

Run the macro on entry to the date form fields to pop up the
calendar/date

Sub Calendar()
frmCalendar.Show
End Sub

Using the code from my web site, make the changes as required

Private Sub Calendar1_Click()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
oFld(GetCurrentFF.name).Result = Format(Calendar1.Value, "dd mmmm
yyyy") Unload Me
End Sub

Private Sub CmdClose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Calendar1.Value = Date 'start with today's date
End Sub
 
D

Dale

spoke too soon, word 2k is happy, word 2007 isn't, errors out on
closing the form and the protect line of code
--



Dale wrote:
Graham, I did go with unprotecting and protecting the document to open
the email form. It works well, and because my save event happens
before the show.form macro, the saved document is also protected. It
may not be elegant but it works and my life can start again!!
--



Dale wrote:
Graham,
One last time I hope..this form is going to be the death of me, it
shouldn't have been this difficult! I designed this form in word
2007, but have since had to redesign in 2000 as we have a wide
disparity of office versions. My newest problem: I'm trying to open
a form and I'm not sure why this form would be any different than the
pop up calendar, but I am now getting an error when using
(semail.show) which is an "email" form, on the protected document.

The error is a runtime error 4605 "method or property is not avaiable
as the object or property it refers to is in a protected area of the
document". The code works in 2007 but it appears 2000 is less
tolerant! Again I don't see how this is any different from opening a
calendar form. Do I have to unprotect the document, open the form run
the email routine behind the form, close the form and then protect
the document, which is not desirable as the saved document would also
be unprotected.

thanks....very close to disabling all macros and going plain jane!!
--



Graham Mayor wrote:
You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Thank you so much Graham, I would never have come up with that and
I've been trying for 2 days!!
--


Graham Mayor wrote:
Public Function GetCurrentFF() As Word.FormField
Set rngFF = Selection.Range
rngFF.Expand wdParagraph
For Each fldFF In rngFF.FormFields
Set GetCurrentFF = fldFF
Exit For
Next
End Function

Run the macro on entry to the date form fields to pop up the
calendar/date

Sub Calendar()
frmCalendar.Show
End Sub

Using the code from my web site, make the changes as required

Private Sub Calendar1_Click()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
oFld(GetCurrentFF.name).Result = Format(Calendar1.Value, "dd mmmm
yyyy") Unload Me
End Sub

Private Sub CmdClose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Calendar1.Value = Date 'start with today's date
End Sub
 
D

Dale

Ok thanks figured it out..have to have a formfield selected to protect
the document...funny how the different versions behave differently with
the same code.
--



Dale wrote:
How do a reference the formfield on a protected form to insert a date
from a datepicker? I have 3 date fields, it seems I can insert a date
based on the field selected i.e.
selection.formfields("x")=calendar1.value
Any help is appreciated.
thanks
--
 
D

Doug Robbins - Word MVP

What is the exact line of code and what is the error message?

--
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
 
D

Doug Robbins - Word MVP

Selecting a formfield is not necessary. The following will protect the
active document for filling in forms even when there are no formfields in
the document.

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset

--
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
 
D

Dale

This is the only way I can get it to work
ActiveDocument.Unprotect
sEmail.Show
ActiveDocument.FormFields("RequestYes").Select
ActiveDocument.Protect wdAllowOnlyFormFields, True

Tried replacing True with NoReset and it doesn't compile.
--



Doug Robbins - Word MVP wrote:
Selecting a formfield is not necessary. The following will protect
the active document for filling in forms even when there are no
formfields in the document.

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset

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

Ok thanks figured it out..have to have a formfield selected to
protect the document...funny how the different versions behave
differently with the same code.
--


Dale wrote:
How do a reference the formfield on a protected form to insert a
date from a datepicker? I have 3 date fields, it seems I can
insert a date based on the field selected i.e.
selection.formfields("x")=calendar1.value
Any help is appreciated.
thanks
--
 

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