Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using + & - to increment date

Status
Not open for further replies.

gnosis13

Programmer
Jul 13, 2001
263
US
I would like to add functionality that would allow the user to press + or - to increment or decrement the date in a field. If I can get this to work, there are a couple of other fields I would like to do the same way so the code needs to sniff the keystroke at the field level. This is what I have so far:

Private Sub txt_presave_date_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
Case 43
txt_presave_date = txt_presave_date + 1
Case 45
txt_presave_date = txt_presave_date - 1
Case Else
KeyAscii = 0
End Select

End Sub

This works except that it first puts the keystroke in the field. For example; pressing + puts a plus sign in the field, if you press the ESC key, the date gets incremented.

How do I get this to NOT put the keystroke in there and just increment the date?


A+, N+, MCP
 


Hi,

That's because it what you coded.

Trouble is, you appear NOT to have a real date -- just a string that maybe LOOKS like a date to you.

Why do Dates and Times seem to be so much trouble? faq68-5827

Use real dates!

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Maybe I didn't explain correctly. The date works fine. In fact, I got code all over the place that increments the dates in a similar fashion and they work fine (not all my code). In my example, there is a "Save" button that the user presses when done done that writes the record to the DB, the date copies fine.

I would just like to press + or - key to change the date. Like I said, the above code basically works. If you press + it puts a plus in the box, pressing ESC the box displays the date + 1 day just like it should.


A+, N+, MCP
 

Here's the short of it
Code:
Private Sub txt_presave_date_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii
        Case 43
            txt_presave_date = CDate(txt_presave_date) + 1
            KeyAscii = 0
        Case 45
            txt_presave_date = CDate(txt_presave_date) - 1
            KeyAscii = 0
    End Select

End Sub

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top