Insert current date into form fields 
Author Message
 Insert current date into form fields

I have a form that prompts the user for a number of dates.  The
"standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
on a user form.  Is there a way to create a keystroke to insert the
current date and then be able to use this while the form is open?  Or
perhaps a button that can remember the field the user was in and then
insert the date into that field?

Thanks,
Julie.



Fri, 07 Nov 2003 14:28:19 GMT  
 Insert current date into form fields
Hi Julie,

I assume that we are talking about a UserForm and not formfields in a
protected document.

If it is a UserForm, why not include code in the Initialize event to set the
value of the control to Date.

TextBox1.Text = Date

If it's a formfield, why not have a macro run on entry to the field to set
the result of the formfield to Date

ActiveDocument.FormFields("Text1").Result = Date

Add a Format function to Date to get a particular date format, e.g.

Format(Date, "MMMM d, yyyy")

for May 21, 2001

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> I have a form that prompts the user for a number of dates.  The
> "standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
> on a user form.  Is there a way to create a keystroke to insert the
> current date and then be able to use this while the form is open?  Or
> perhaps a button that can remember the field the user was in and then
> insert the date into that field?

> Thanks,
> Julie.



Fri, 07 Nov 2003 18:51:23 GMT  
 Insert current date into form fields
Hi Doug,

Yes, it's a UserForm, not formfields.  I don't want all the fields to
initialise to the current date - the user will probably only want to
put it in one box out of 15 when they go into the form.  I have ended
up putting a small button next to each field that will insert the date
properly formatted (Format(Now,"dd/mm/yyyy")) in the field, but I
would really like to have a keystroke that would do the same thing if
at all possible!

Thanks,
Julie.

Quote:

> Hi Julie,

> I assume that we are talking about a UserForm and not formfields in a
> protected document.

> If it is a UserForm, why not include code in the Initialize event to set the
> value of the control to Date.

> TextBox1.Text = Date

> If it's a formfield, why not have a macro run on entry to the field to set
> the result of the formfield to Date

> ActiveDocument.FormFields("Text1").Result = Date

> Add a Format function to Date to get a particular date format, e.g.

> Format(Date, "MMMM d, yyyy")

> for May 21, 2001

> Please post any follow-up or new questions to the Newsgroups so that others
> may benefit therefrom or contribute thereto.

> Hope this helps,
> Doug Robbins - Word MVP


> > I have a form that prompts the user for a number of dates.  The
> > "standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
> > on a user form.  Is there a way to create a keystroke to insert the
> > current date and then be able to use this while the form is open?  Or
> > perhaps a button that can remember the field the user was in and then
> > insert the date into that field?

> > Thanks,
> > Julie.



Sat, 08 Nov 2003 11:19:18 GMT  
 Insert current date into form fields
Hi Julie,

TextBox1.Text = Date

will only put the date in TextBox1, not all 15

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Hi Doug,

> Yes, it's a UserForm, not formfields.  I don't want all the fields to
> initialise to the current date - the user will probably only want to
> put it in one box out of 15 when they go into the form.  I have ended
> up putting a small button next to each field that will insert the date
> properly formatted (Format(Now,"dd/mm/yyyy")) in the field, but I
> would really like to have a keystroke that would do the same thing if
> at all possible!

> Thanks,
> Julie.




Quote:
> > Hi Julie,

> > I assume that we are talking about a UserForm and not formfields in a
> > protected document.

> > If it is a UserForm, why not include code in the Initialize event to set
the
> > value of the control to Date.

> > TextBox1.Text = Date

> > If it's a formfield, why not have a macro run on entry to the field to
set
> > the result of the formfield to Date

> > ActiveDocument.FormFields("Text1").Result = Date

> > Add a Format function to Date to get a particular date format, e.g.

> > Format(Date, "MMMM d, yyyy")

> > for May 21, 2001

> > Please post any follow-up or new questions to the Newsgroups so that
others
> > may benefit therefrom or contribute thereto.

> > Hope this helps,
> > Doug Robbins - Word MVP


> > > I have a form that prompts the user for a number of dates.  The
> > > "standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
> > > on a user form.  Is there a way to create a keystroke to insert the
> > > current date and then be able to use this while the form is open?  Or
> > > perhaps a button that can remember the field the user was in and then
> > > insert the date into that field?

> > > Thanks,
> > > Julie.



Sat, 08 Nov 2003 17:34:24 GMT  
 Insert current date into form fields
Hi Julie,

The following code will allow the user to put the current date in  TextBox1
by pressing Ctrl-D. TextBox1 needs to have the focus when pressing the key
combination.

--------------------------------------------------------------

Private Declare Function GetAsyncKeyState Lib "user32" _
    (ByVal vKey As Long) As Integer

Private Const VK_CONTROL = &H11

Private Sub TextBox1_KeyDown _
    (ByVal KeyCode As MSForms.ReturnInteger, _
     ByVal Shift As Integer)

If GetAsyncKeyState(VK_CONTROL) < 0 Then
    If KeyCode = 68 Then
        KeyCode = 0
        TextBox1.Text = Format(Date, "dd/mm/yyyy")
    End If
End If

End Sub

--------------------------------------------------------------

Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.


Quote:
> Hi Doug,

> Yes, it's a UserForm, not formfields.  I don't want all the fields to
> initialise to the current date - the user will probably only want to
> put it in one box out of 15 when they go into the form.  I have ended
> up putting a small button next to each field that will insert the date
> properly formatted (Format(Now,"dd/mm/yyyy")) in the field, but I
> would really like to have a keystroke that would do the same thing if
> at all possible!

> Thanks,
> Julie.




Quote:
> > Hi Julie,

> > I assume that we are talking about a UserForm and not formfields in a
> > protected document.

> > If it is a UserForm, why not include code in the Initialize event to set
the
> > value of the control to Date.

> > TextBox1.Text = Date

> > If it's a formfield, why not have a macro run on entry to the field to
set
> > the result of the formfield to Date

> > ActiveDocument.FormFields("Text1").Result = Date

> > Add a Format function to Date to get a particular date format, e.g.

> > Format(Date, "MMMM d, yyyy")

> > for May 21, 2001

> > Please post any follow-up or new questions to the Newsgroups so that
others
> > may benefit therefrom or contribute thereto.

> > Hope this helps,
> > Doug Robbins - Word MVP


> > > I have a form that prompts the user for a number of dates.  The
> > > "standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
> > > on a user form.  Is there a way to create a keystroke to insert the
> > > current date and then be able to use this while the form is open?  Or
> > > perhaps a button that can remember the field the user was in and then
> > > insert the date into that field?

> > > Thanks,
> > > Julie.



Sat, 08 Nov 2003 22:30:33 GMT  
 Insert current date into form fields
Hi ibby,

Yes, this is good!  If I wanted to change the key to use (in this
instance Ctrl-D is good, but I'm thinking I might want to use this for
other things too), which bit would I look at?  Thanks for your help.

Julie.

Quote:

> Hi Julie,

> The following code will allow the user to put the current date in  TextBox1
> by pressing Ctrl-D. TextBox1 needs to have the focus when pressing the key
> combination.

> --------------------------------------------------------------

> Private Declare Function GetAsyncKeyState Lib "user32" _
>     (ByVal vKey As Long) As Integer

> Private Const VK_CONTROL = &H11

> Private Sub TextBox1_KeyDown _
>     (ByVal KeyCode As MSForms.ReturnInteger, _
>      ByVal Shift As Integer)

> If GetAsyncKeyState(VK_CONTROL) < 0 Then
>     If KeyCode = 68 Then
>         KeyCode = 0
>         TextBox1.Text = Format(Date, "dd/mm/yyyy")
>     End If
> End If

> End Sub

> --------------------------------------------------------------

> Hope this helps.
> ibby

> Please post replies or follow-ups to the **newsgroup** so that participants
> may benefit or contribute.



> > Hi Doug,

> > Yes, it's a UserForm, not formfields.  I don't want all the fields to
> > initialise to the current date - the user will probably only want to
> > put it in one box out of 15 when they go into the form.  I have ended
> > up putting a small button next to each field that will insert the date
> > properly formatted (Format(Now,"dd/mm/yyyy")) in the field, but I
> > would really like to have a keystroke that would do the same thing if
> > at all possible!

> > Thanks,
> > Julie.



> > > Hi Julie,

> > > I assume that we are talking about a UserForm and not formfields in a
> > > protected document.

> > > If it is a UserForm, why not include code in the Initialize event to set
>  the
> > > value of the control to Date.

> > > TextBox1.Text = Date

> > > If it's a formfield, why not have a macro run on entry to the field to
>  set
> > > the result of the formfield to Date

> > > ActiveDocument.FormFields("Text1").Result = Date

> > > Add a Format function to Date to get a particular date format, e.g.

> > > Format(Date, "MMMM d, yyyy")

> > > for May 21, 2001

> > > Please post any follow-up or new questions to the Newsgroups so that
>  others
> > > may benefit therefrom or contribute thereto.

> > > Hope this helps,
> > > Doug Robbins - Word MVP


> > > > I have a form that prompts the user for a number of dates.  The
> > > > "standard" MS shortcut Ctrl-; doesn't work in Word at all, let alone
> > > > on a user form.  Is there a way to create a keystroke to insert the
> > > > current date and then be able to use this while the form is open?  Or
> > > > perhaps a button that can remember the field the user was in and then
> > > > insert the date into that field?

> > > > Thanks,
> > > > Julie.



Sun, 09 Nov 2003 07:40:50 GMT  
 Insert current date into form fields
Hi Julie,

Quote:
> Yes, this is good!  If I wanted to change the key to use (in this
> instance Ctrl-D is good, but I'm thinking I might want to use this for
> other things too), which bit would I look at?  Thanks for your help.

The bit of code that specifies "D"is the following:

    If KeyCode = 68 Then

For Ctrl-A you would use:

    If KeyCode = 65 Then

For Ctrl-Z use:

    If KeyCode = 90 Then

I'll leave you to fill in the gaps.

--
Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.



Sun, 09 Nov 2003 13:24:36 GMT  
 Insert current date into form fields

Quote:

> Hi Julie,

> > Yes, this is good!  If I wanted to change the key to use (in this
> > instance Ctrl-D is good, but I'm thinking I might want to use this for
> > other things too), which bit would I look at?  Thanks for your help.

> The bit of code that specifies "D"is the following:

>     If KeyCode = 68 Then

> For Ctrl-A you would use:

>     If KeyCode = 65 Then

> For Ctrl-Z use:

>     If KeyCode = 90 Then

> I'll leave you to fill in the gaps.

Ah, of course - I should have recognised the ASCII code!

Thanks again for your help.

Julie.



Tue, 11 Nov 2003 12:15:55 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Inserting current date into a contact's note field

2. Changing a Calculate field (Date) depending on Current date

3. Problem with format on insert autotext, and in inserting elements with form fields

4. Insert current date and time

5. Can't put current date in an SQL INSERT

6. Updating Calculated field depending on Current Date

7. When value changes, update other field with current date

8. Insert date and time field into MS Access with SQL

9. Problem inserting record with date field

10. INSERT INTO and UPDATE date field

11. Inserting a date field into SQL

12. INSERT query fails with date field

 

 
Powered by phpBB® Forum Software