Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: SendKeys (A2K)

  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SendKeys (A2K)

    Small question in spite of a lot of hatred aimed at SendKeys. I came upon a neat routine that has the following in it:

    SendKeys Now & " : " '* Inserts the current date and time

    Which looks like this: 7/5/2004 9:23:24 PM :
    It would be a little neater if I could format it to look like: 05-Jul-04 or even July 5, 2004
    Any suggestions?
    Cheers,
    Andy

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: SendKeys (A2K)

    I don't see why you're bothering with SendKeys, since you can do the same thing without it. Ctrl+; inserts the current date into a field in Access without requiring sendkeys. That's a built-in shortcut.

    The reason SendKeys gets scorned is because it is somewhat archaic and there are usually better and cleaner ways to do it which also allow error trapping. Where are you trying to insert the date and how, with VBA, with an Access macro, or what?
    Charlotte

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    In this particular scenario the SendKeys is executed from a button which inserts the cursor into a memo field, emits the date, and then drops down a line to start the note. The next time it is used, and it will be, the cursor will go to the top of the memo field, insert a date above the previous entries thereby becoming the most recent annotated addition to the memo. It is, like myself, archaic, sometimes scorned, but neat. So...... is there any way that I can use SendKeys with a formatted date as I mentioned above? And I do know about Ctrl+ which is right up there with Ctrl' for usefullness.
    Cheers,
    Andy

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SendKeys (A2K)

    You can use

    SendKeys Format(Now, "dd-mmm-yy h:mm AM/PM") & ...

    or something like that.

  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Hans,

    It was exactly like that. Thanks again for your kind and directly to the point answer to my original question.
    Cheers,
    Andy

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Further note to anyone who might be interested. I did not create this routine to start with and therefore do not take any credit for it. But, this is how I reworked it to suit my needs. Again, it is to go into a memo field, insert current date and time and then drop down a line to enter the note. And the next time around, to go to the top of notes:

    Private Sub EnterCurrentNote_Click()
    On Error Resume Next
    Me.SetFocus
    DoCmd.GoToControl "txtSRNCurrent"' Name of control holding memo field
    SendKeys Format(Now, "dd-mmm-yy h:mm AM/PM") ' Inserts date &time
    SendKeys "^{ENTER}{LEFT}{Enter}" ' Drops down to next line to enter note
    Err.Clear
    On Error GoTo 0
    End Sub

    This works perfectly when in a main or parent form. If you try and use it in a subform, you have to insert the Control's name in the Me.SetFocus, in this case it would be Me.txtSRNCurrent.SetFocus. That's the good news. The bad news is, I'm having a problem forcing it to the top of the Memo field. It just does not want to cooperate so far. If I figure it out, I will add it to this post.

    Thanks to all that contribute.
    Cheers,
    Andy

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SendKeys (A2K)

    Try replacing

    Me.SetFocus
    DoCmd.GoToControl "txtSRNCurrent"'

    by

    Me.txtSRNCurrent.SetFocus
    Me.txtSRNCurrent.SelLength = 0
    Me.txtSRNCurrent.SelStart = 0

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: SendKeys (A2K)

    Hi Andy,
    This is a somewhat convoluted way of creating a series of date organized notes and storing them all in a single memo field. The usual suggestion in this situation is that a separate table be created for notes and given a system generated timestamp. There are a couple of issues with the memo field approach. First, it is very easy for a user to accidently edit old parts of the note and create havoc. Second there isn't any way of tracking who did what in terms of notes. We usually lock a note record once it has been entered, and require that any corrections be done in a new note. Since you appear to have inherited this design, you don't have much choice, but for others reading this thread, I would discourage the use of this technique.
    Wendell

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: SendKeys (A2K)

    As I said, you don't need SendKeys for this. Instead try this:

    Me.txtSRNCurrent = Format(Now, "dd-mmm-yy h:mm AM/PM") & vbcrlf & Me.txtSRNCurrent
    Charlotte

  10. #10
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Hans,

    My 'final' (famous last words) version of your accumulated suggestions looks like this for anybody who's been looking over our shoulders:

    Private Sub EnterCurrentNoteSub_Click()
    On Error Resume Next
    Me.txtCurrentNoteSub.SetFocus
    Me.txtCurrentNoteSub.SelLength = 0
    Me.txtCurrentNoteSub.SelStart = 0
    DoCmd.GoToControl "txtCurrentNoteSub"
    SendKeys Format(Now, "mmmm d, yyyy @ h:mm AM/PM")
    SendKeys "^{ENTER}{LEFT}{Enter}"
    Err.Clear
    On Error GoTo 0
    End Sub

    Which when triggered gives me: July 6, 2004 @ 1:02 PM
    Which makes me a happy camper. Thanks again for taking the time to follow up.
    Cheers,
    Andy

  11. #11
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Charlotte,

    I tried your suggestion and did not quite get the results that I wanted. With text box names changed my final version using your code looked like this:

    Private Sub EnterMaintNoteSub_Click()
    On Error Resume Next
    Me.txtMaintNoteSub.SetFocus
    DoCmd.GoToControl "txtMaintNoteSub"
    Me.txtMaintNoteSub = Format(Now, "dd-mmm-yy h:mm AM/PM") & vbCrLf & Me.txtMaintNoteSub
    Err.Clear
    On Error GoTo 0
    End Sub

    Which when triggered gave me: 06-Jul-04 1:05 PM, left the field highlighted and did not return to the next line. If I entered a note and then triggered it again as if to enter a 2nd note at a different time, it would wipe out previous note entries, put the new date and the old date in and remain highlighted.

    If I've misconstrued your instructions I apologize. For the moment, Hans' version appears to be doing the job perfectly, so I'll be using it. Thanks for taking the time to respond.
    Cheers,
    Andy

  12. #12
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Wendell,

    Thanks for jumping in with your sage advice. It would be a convoluted tale to give you all the background and excruciating details that make my version, using Hans' new and improved code, the most viable solution at the present. But your point is well taken with respect to someone who is starting out fresh with this problem and has not had my particular yoke put in place.

    Again, I hope the over-the-shoulder watchers have picked up as much good stuff as I have today.
    Cheers,
    Andy

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SendKeys (A2K)

    You don't need the line <code>DoCmd.GoToControl "txtCurrentNoteSub"</code> any more. It is equivalent to the line <code>Me.txtCurrentNoteSub.SetFocus</code> above it.

  14. #14
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SendKeys (A2K)

    Hans,

    Thanks kindly. Where do you get the time?
    Cheers,
    Andy

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SendKeys (A2K)

    >> Where do you get the time?

    I borrow it, but rates are steep! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •