Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Unanswered: Using F5 and F6 keys to enter date and Time

    I have used an Access DB where the F5 and F6 key was used to input the current date (F5) and the Current Time (F6).

    I am designing a db and need to use these shortcuts on the database, but I am not sure how to do this, can anyone help me with this.
    Will Dove
    working hard is better then hardly working ...

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    Both the F5 and F6 keys, are assigned to different functionality alredy

    F5 - go to record number box in forms, refresh database window, switch to form view from design view

    F6 - move to task pane, switch beween lower/upper part of window (design view) (with ctrl - cycle between open windows)

    Why not teach the user the default shortcut keys for date and time in stead?

    Ctrl+Semicolon (";")
    Ctrl+Shift+Colon (":")
    Roy-Vidar

  3. #3
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Thanks

    Thanks, I am still learning all the shortcuts and what not in access. I am still learing new things in Access everyday.

    Thanks again
    Will Dove
    working hard is better then hardly working ...

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    RoyVider is right...the function keys are already asigned to the environment but MS-Access provides a simple method to utilize these keys to whatever you like on the fly.

    The current asignment is global and you may not want to change that. You obviously want this to be Form specific so let's assume you have a Form. On this Form is a TextBox named DateField and another TextBox named TimeField.

    Place your form into Design View. Select the Events tab located in the Properties window. Locate the Key Preview event and set it to Yes.

    Now...in the Form's On Key Down event set it to Event Procedure and place this code into the code module for this event.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       Select Case KeyCode
         Case vbKeyF1
         Case vbKeyF2
         Case vbKeyF3
         Case vbKeyF4
         Case vbKeyF5
            Me.DateField = Date
         Case vbKeyF6
            Me.TimeField = Time
         Case vbKeyF7
         Case vbKeyF8
         Case vbKeyF9
         Case vbKeyF10
         Case vbKeyF11
         Case vbKeyF12
         Case vbKeyF13
         Case vbKeyF14
         Case vbKeyF15
         Case vbKeyF16
       End Select
    End Sub
    You don't need to have all the Case options that I have added here. You really only need the Case vbKeyF5 and the Case vbKeyF6. I simply placed all of them here so that you can utilize any you like for other possible purposes.

    Do a search iin Access help for KeyCode Constants for all the other keys you can use.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    It's of course a matter of opinion and preferences ...

    I'm more conserned about altering default functionality - say the users are used to the default shortcut of specifying a record position to move to (F5 - type a number - Enter), then in one form this will not do any moving, but insert a date.

    Also, if you don't test for it, hitting F5 or F6 with any combination of the Alt, Shift or Ctrl keys, will also enter date or time into these controls. Wouldn't one also test the Shift parameter?

    I'd be more inclined to use buttons, which are both visually present on the form, and where one can use a caption with ampersand, making it also a shortcut. A caption of "Insert d&ate" will make Alt+a a shortcut for this button.

    But again, opinions, preferences ...
    Roy-Vidar

  6. #6
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Red face Error Message

    This is the code I used to add to the form as per your instructions.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       Select Case KeyCode
         Case vbKeyF5
            Me.ShiftDate = Date
         Case vbKeyF6
            Me.starttime = Time
         End Select
    End Sub
    Now I am getting an Error Message

    Code:
    The search key was not found in any record
    followed by

    Code:
    You tried to commit or roolback a transaction without first beginning a transaction.
    Both of those are in the VB editor, and the Form itself when I try to close it. I also get the following on the form.
    Code:
    RESERVED ERROR
    Will Dove
    working hard is better then hardly working ...

  7. #7
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    When you fiddle with keys, It's sometimes an idea to cancel the key

    KeyCode = 0

    But those errormessages doesn't seem to relate to default functionality of F5/F6.
    Roy-Vidar

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487
    Here is a small sample....I suppose it all depends upon how you have your form set up and how the data is bound to your table(s).

    .
    Attached Files Attached Files
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  9. #9
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    I suggest you pursuade the users back towards "standard" functionality. As your users become accustomed to the custom meanings of functional keys, they may start thinking that is how Access normally works and will run into trouble when they use other Access apps.

    Ok, the real reason is this: if you do it now, you'll be expected to continue doing it in the future, which means more work for you. You'll have to remember that some groups get it this way and other groups don't, etc. etc. etc. And your successors will use your name as a swear word every time they have edit your work.

    Using a command button on the form is a great idea - they can click the button or use the Alt Key. You can also use a bit of code to automatically place the values in the control for the user.

    This is, as always, just another opinion.

  10. #10
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Thanks for the help,and suggestions

    The main reason I am looking to change this to F keys is to make it simple for the guys on the ground. They don't use Access outside of this program I have developed for them, to put it lightly, most had not even heard of Access until me.

    The database is designed to elimate them writting out 20 reports a night. Most of them do not have a College education, and will not ever get one.

    On another note the F keys will assist in speed for the users, as they are all in law enforcement, and will be entering over 50 entires a night, each. They have complained of having to type in the date and time over and over for each entry.

    The only problem adding a F key feature will present is having to recode the reports.

    I need the reports to run from 7pm to 7am the following day. and some others to run at different times 24 hours a day. I am still considering how to work these reports so they print correctly.

    i.e.

    Officer on Duty at 2200 on 1/1/06
    Officer arrest individual at 0200 on 1/2/06

    Now I need these to be in order based on the time the officer started his shift, not based on time of day, (2200, 2245, 0140, 0450, etc..) and I need them to print on one report for 1/1/06 and not have anything print on the 1/2/06 report that was covered by the officer that went to work at 2200 on 1/1/06.


    This is a big project for me, but a lot of learning as well.

    thanks
    Will Dove
    working hard is better then hardly working ...

  11. #11
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    ok, a few things to suggest in your project.

    1) I assume they are using the mouse already, you could give them a "simplified calendar control". I have warehouse personel do data entry on received date by placing a text box between to little arrow buttons. The text box contains today's date by default, the down arrow decreases the date by one day and the up arrow increases the date by one day. So, if it was received Friday but not stocked until Monday, they click the down arrow 3 times. Your officers would only need to click it once at most.

    2) You could do the same for the time field, or search for a "clock control" that allows them to click on the dial (similar to the control your PC uses in the Set Date/Time panel).

    3) Your non-date aligned 24 report periods will be pretty easy if you add a field to your select query that is "TRUE" for records falling into the correct span of time and add this field to your report's filter. There are a handful of ways to get the time spans into the query, depending on if you want it hard coded or user definable.

    4) To solve putting the value in order, store the time and date of the event as one field. Access knows that "1/1/06 22:00" comes before "1/2/06 02:00". If you must store date and time seperately, sort by Date THEN sort by time.

    I can't offer assistance with the F keys - I haven't used the F keys since I was writing code in GW Basic .... oh Lord, I just dated myself!

    tc

  12. #12
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    When I was starting out, back in the days of DOS and batch files (like tcace, I just dated myself) I became very frustrated with myself because everything took forever to learn, until I figured out that many of the programmers were writing apps for other programmers, not the non-techie user. I swore I would never do that! The fact of the matter is, most people aren't power users! They're everyday guys and gals who jobs only abuts on computers tangentally. You've got to design your apps with the user always foremost in mind!

    Have said that, a couple of things occured to me. If these dates/times are going into ShiftDate and StartTime, why not simply have the date or time filled in on entering the control? For example:

    Private Sub ShiftDate_Enter()
    'When the Date control receives focus
    'If the field is blank
    If IsNull(Me.ShiftDate) Or Me.ShiftDate.Value = "" Then
    Me.ShiftDate.Value = Date()
    End If

    Also, vis a vis the F Key discussion, an approach I've used in the past in order to enter date or time in a memo field (where users notes are added over days or months) is to have the F Key assigned a special function only when it is used in certain fields. In a module I do:

    Public ShortCutSwitch as Boolean

    Then when the Memofield gets focus:

    ShortCutSwitch = True

    Then when the Memofield loses focus:

    ShortCutSwitch = False

    Then

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyF4
    If ShortCutSwitch = True
    'Place your code in here for temporary function change
    End If
    End Select
    End Sub

    Now the F4 Key only behaves in a certain way when it's in the given memofield.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  13. #13
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Thumbs up I think I figured it out

    I found that I can use this code by breaking it down into simple code on each text box instead of the whole form.

    Code:
     Select Case KeyCode
         Case vbKeyF5
            Me.ShiftDate = Date
         Case vbKeyF6
            Me.starttime = Time
         End Select
    it is working now thanks.
    Will Dove
    working hard is better then hardly working ...

  14. #14
    Join Date
    Dec 2005
    Location
    Somewhere on the 3rd Rock
    Posts
    93

    Angry Maybe Not

    Looks Like I keep getting the same errors once I change the shortcuts to the F5 F6 key. what could be causing this. I am using MS Access 2002 file format.

    Quote Originally Posted by saileast
    I found that I can use this code by breaking it down into simple code on each text box instead of the whole form.

    Code:
     Select Case KeyCode
         Case vbKeyF5
            Me.ShiftDate = Date
         Case vbKeyF6
            Me.starttime = Time
         End Select
    it is working now thanks.
    Will Dove
    working hard is better then hardly working ...

  15. #15
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Although I've never seen it documented anywhere, Access doesn't let you re-assign all keys. F1 will remain the Help key, even if you assign another function to it. Sometimes whether or not it will allow re-assignment depends on what features you're you're using on a form. First you said the re-assignment wasn't working, then it was, and now it's not again! My guess is that the F6 key is working, but the F5 isn't. I'm basing this on the error message you reported: The search key was not found in any record. If your form has the standard records navigation stuff at the bottom of your form (Record selector and Navigation Buttons) and you press F5, the cursor moves into the Record's Number box. You then enter the number of the record you want and hit enter and it moves to that record. If you've removed these items from your form and made your own navigation buttons, re-assigning F5 will work.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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