Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

input date from calendar in textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
erik - 24 Feb 2005 14:28 GMT
hello everybody,

On the internet I found a program to enter a date in my document by clicking
on a calendar userform. It works fantastically, but I would like to use it a
little different and don't exactly know how.

In my document I have textboxes from the forms toolbar (grey fields you have
to fill out). I want to open the calendar when I click on the textbox (i use
a macro when assessing the box) and when I select the date it has to be
inserted within the grey field, keeping the grey field and bookmark.

A few issues: When I have locked the page my program says it cannot write to
a locked position. When I have the page 'open' the date overwrites the grey
field and the date cannot be altered by using the macro as I meant it.

Who has a suggestion for me? The code I use is:

Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
   Selection.Text = Format(Calendar1.Value, "dd mmmm yyyy")
   Unload Me
End Sub

Private Sub cmdClose_Click()
' Close the form without entering a date if the user
' presses the [ESCAPE] key
   Unload Me
End Sub

Private Sub UserForm_Initialize()
' If selection is a date show the same date, otherwise show
' today's date.
   If IsDate(Selection.Text) Then
       Calendar1.Value = DateValue(Selection.Text)
   Else
       Calendar1.Value = Date
   End If
End Sub

Hope you can help me!!!
thnx,
Erik
Jay Freedman - 24 Feb 2005 23:19 GMT
Hi Erik,

The problem is that your code's "Selection.Text =" statement is trying
to replace the field itself, where it should only be trying to set its
data. Try it this way instead:

Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
   Dim FFname As String
   FFname = Selection.Bookmarks(Selection.Bookmarks.Count).Name
   ActiveDocument.FormFields(FFname).Result = _
       Format(Calendar1.Value, "dd mmmm yyyy")
   Unload Me
End Sub

If you only have the one field in the document where you need to
insert the date, you can simplify it by just hard-coding the field
name into the macro, something like this:

Private Sub Calendar1_Click()
' Transfer date selected on calendar to the insertion
' insertion and close UserForm.
   ActiveDocument.FormFields("DateField").Result = _
       Format(Calendar1.Value, "dd mmmm yyyy")
   Unload Me
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>hello everybody,
>
[quoted text clipped - 39 lines]
>thnx,
>Erik

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.