Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date field

Status
Not open for further replies.

BSando

Technical User
Jun 29, 2003
73
0
0
AU
Hi All,

I have a label in my word doco that I want the users to click on and this fills in a textfield with the date. It odes works with in reason, when I lock the form I get a message telling me it is a protected area of the document. what do I need to change so it works while the form is locked?

Thank you in advance


Private Sub label1_Click()

Selection.GoTo what:=wdGoToBookmark, Name:=("text23")

Selection.InsertDateTime datetimeformat:="DDDD, d MMMM, yyyy"

End Sub

Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 

Rather than answer your question directly, I would like to suggest a revision to your basic idea. Rather than have your users enter any data in this textfield, why don't you set it up as an automatic entry using the same format?


Code:
Private Sub label1
Selection.GoTo what:=wdGoToBookmark, Name:=("text23")
Selection.InsertDateTime datetimeformat:="DDDD, d MMMM, yyyy", insertas field:=false
End Sub

This will automatically give you the desired date format for the current date, without having to worry about unprotecting the document or getting any user involvement. To me this seems a better solution. Note that the only changes needed were to remove the "click event" from the sub name, and to add the insertasfield:=false command. However, if you still want or need to have the user involved post back and we can tackle the password problem.

I have tested this, and it works every time no matter what the password status of the document.

[glasses]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
BSando,

I notice that you logged on sometime yesterday. Does my solution work for you, or do we need to discuss passwords?

[ponder]

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
Hi BSando,

Try:
Code:
Private Sub label1_Click()
ThisDocument.Bookmarks("Text23").Range.Fields(1).Result.Text = Format(Now, "ddd d, MMM yyyy")
End Sub
Cheers

[MS MVP - Word]
 
I'm having difficulty understanding the setup here.

You have a label in your document - that must be an ActiveX control (off the Controls Toolbar).

You have a form that you lock - by this I presume you mean you have protected the document for Forms and you have some FormFields which, by definition, must be unprotected.

You want to populate a textfield - if that were a FormField text field (off the Forms Toolbar) then it would not be protected so it must be some other sort. Is it an ActiveX textbox (off the Controls toolbar)?

Generally speaking, mixing form fields and ActiveX controls doesn't work well, but can you expand a little on what you actually have - and what you actually want?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Hi Tony,

My take on this is that BSando's document has both an ActiveX control and a text formfield. BSando wants to protect the document and use the ActiveX control to update the formfield.

Your statements
You have a form that you lock - by this I presume you mean you have protected the document for Forms and you have some FormFields which, by definition, must be unprotected.

You want to populate a textfield - if that were a FormField text field (off the Forms Toolbar) then it would not be protected so it must be some other sort.
are confusing and, on first reading, are at odds with the way formfields work - they only work when the document is protected for forms.

Cheers

[MS MVP - Word]
 
Am I being thick today? When a document is protected for forms, formfields themselves are not protected (whilst other content, at least in the same section, is)so code that tries to update a formfield will not get a message that it is trying to update a protected area of the document so the bookmark can not be a formfield.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
macropod & Tony,

This may all be wasted effort. I know BSando logged on after my original posting and it appears he is getting email notification about this thread but he is not acknowledging any of these posts. Based on the data available, this seems to be a pattern: ask for help and don't take time to admit that you've read what help has been offered, much less issue a "Thanks".

I am certainly going to think twice, and then maybe one more time, before offering any further help. I'd at least like to know whether or not what I have posted was useful rather than being left spinning in the wind, wondering if it was just so much wasted effort.

[thumbsdown]


----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
Am I being thick today?
Apparently. When a document is protected for forms, formfields themselves are protected - that's what makes them work, instead of being vulnerable to being overtyped.

Cheers

[MS MVP - Word]
 
OK, I'm being thick :)

I really should know this having just had to unprotect a Form to highlight a field, but this side of the world 2+2 seem to equal about 2.1 at the moment.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Hi All.

Thank you for your help.
For now I have gone with macropod's suggestion and just make it the current date.
I did try to update the formfield by clicking on a label but that didn't work.

Thanks again

Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 
Hi BSando,

Did you want to use a different date? Your post gave no indication of this. If so, all you need to do is to insert your date after the '=' in:
Code:
ThisDocument.Bookmarks("Text23").Range.Fields(1).Result.Text =
Cheers

[MS MVP - Word]
 
I just wanted it to give the date the user fills in the form without updating it everytime it is opened

Some people make things happen, some watch while things happen, and some wonder 'What happened?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top