|
|
||||||
|
#1
|
|
|
|
|
Hi and thanks for the help. I am using Access 2003. We consistently use the
dates for yesterday, today and tomorrow. I know that I can type Ctrl+; to get the current date. In Access is there a way to assign keystrokes to automatically get yesterday's date and tomorrow's date? Or a button to use on a form? |
|
|
|
#2
|
|
|
|
|
You can use the KeyPress event of the control on your form to assign a value
to the field. For example: Select Case KeyAscii Case vbKeyY, vbKeyY + 32 Me.[MyDate] = Date - 1 Case vbKeyT, vbKeyT + 32 Me.[MyDate] = Date + 1 End Select |
|
#3
|
|
|
|
|
Buttons are easy: create an Event Procedure that assigns Date()-1 or
Date()+1 to the text box in question. If you want to be able to update more than one text box on your form with the same button, you can use code like the following: If Screen.PreviousControl.ControlType = acTextBox Then Screen.PreviousControl = Date - 1 End If With this, select the text box you want updated, then click on the button. Another approach would be to create shortcut keys by creating an AutoKeys macro. |
|
#4
|
|
|
|
|
Yes.
You can have a button insert and date that Access will recognize. Just place the appropriate code in the button's Click event. Example: Me.txtMyTextbox = Date Me.txtMyTextbox = Date -1 Me.txtMyTextbox = Date + 1 Create 3 buttons and use the appropriate line above for each button. Adjust the name of the textbox to the name or your textbox. You can also create keystrokes to do this. You can turn on KeyPreview in the form's properties and have it check the keys you press in the form's KeyDown event then adjust the entry. You can also use an AutoKeys macro to define shortcut keys. If you use the form event, you would use code similar to this: If Me.ActiveControl.Name = "txtMyTextbox " Then If (Shift And acCtrlMask + acShiftMask) Then Select Case KeyCode Case Asc("1") Me.txtMyTextbox = Date - 1 Case Asc("2") Me.txtMyTextbox = Date Case Asc("3") Me.txtMyTextbox = Date + 1 Case 16, 17 'Ignore the Ctrl and Shift keys until a 3rd key is pressed Case Else MsgBox "Invalid Entry" 'Cancel the key by setting the code to zero KeyCode = 0 End Select End If End If |
|
#5
|
|
|
|
|
Allen ~ A bit more help is needed please. I don't know what to do with the
example you typed. Where do I put that text and how does it make my keys work. I tried putting in the KeyPress Event but nothing happened. "Allen Browne" wrote: [..] |
|
#6
|
|
|
|
|
Douglas, I need a bit more help here too...
Where do I create the Event Procedure and where do I put the code? I tried making a button and attaching the Date()-1 to the button but nothing happened. Thanks for a bit more details. I also tried the AutoKeys macro but what I can't figure out there is where to tell the autokey to get the info for Date()-1. Sorry to be dense. :( "Douglas J Steele" wrote: [..] |
|
#7
|
|
|
|
|
1. Open the form in design view.
2. Right-click the date box, and choose Properties. 3. Set the On Key Press property (Event tab of Properties box) to: [Event Procedure] 4. Click the Build button (...) beside the property. Access opens the Code window. 5. Paste the lines in there. The, pressing the Y key in your date control inserts yesterday's date, and the T key inserts tomorrow's date. |
|
#8
|
|
|
|
|
Add a Command Button to the form, and look at the properties of the button
you just added. (if you've got the wizard icon depressed, so that the Command Button Wizard starts when you add the button, simply click on the Cancel button to get out of the wizard) You'll see a list of Events associated with the control (in fact, there's a tab in the Properties window that will let you limit what you're seeing to only the events. Find the event labelled On Click. The white box to the right of that is actually a combo box: select [Event Procedure] from it, then click on the ellipsis (...) to the right. You'll get taken into the VB Editor, with something like the following added for you: Private Sub Command1_Click() End Sub Simply type those 3 lines of code I showed between those two lines of text, so you end up with something like: Private Sub Command1_Click() If Screen.PreviousControl.ControlType = acTextBox Then Screen.PreviousControl = Date - 1 End If End Sub That's it. You're done. Save the form, and test that it does what you want. In terms of an AutoKeys macro, make sure you have the Macro Name column visible. Put whatever key combination you want to use as your shortcut in the Macro Name column (say ^y for yesterday and ^t for tomorrow), and select SetValue as the Action. In the dialog at the bottom, put [Screen].[ActiveControl] as the Item, and Date() - 1 or Date() + 1 as the expression. Name the macro AutoKeys when you save it, and you're done. |
|
|
| Similar Threads | |
| yesterday, today, tomorrow user friendly dates, possible? Hi, Is it possible to display dates as yesterday, today or tomorrow instead of numeric dates in a list view? Thanks. |
|
| Outlook Today Calendar View Should Dispaly as: Today, TOMORROW, F. In the Outloook Today view. When it lists calendar events, it should show them as follows: Today___________ (Today being Wednesday) All day event.... Tomorrow________ ... |
|
| Outlook Today - tomorrow's appointment displayed as today I have two problems in Outlook Today. Here's the scenario. Today is Saturday 3rd Jan, 2004. In Customize Outlook Today I have "Show this number of days in my calendar as 7... |
|
| Outlook Today bug - it shows tomorrow as today Have only noticed this after upgrading to 2003 but in Outlook Today, it lists several items under 'Today', which is Friday, however those items are actually in the calendar... |
|
| Yesterday I was hanged, Today I was hung and Tomorrow I will be... Yes, I am experiencing the same problem, the debugger hanging all to often, although sometimes it works fine. In the end, I have to use the debugger only when absolutely... |
|
|
All times are GMT. The time now is 03:02 PM. | Privacy Policy
|