Using a spinner to increment a date ??

  • Thread starter Thread starter gaftalik
  • Start date Start date
G

gaftalik

Hi all ,

In a cell which is B2 i have the following date 30-09-2005.Now how can
i assign a spinner to this date which is 38625 in order to increment 1
day at a time knowing that the spinner accepts maximum value as 30000
?
Any smart solution ?

I dont know much about VBA but able to paste a code if someone can
explains .

Thank you very much .
 
g,

Link the spinner to Cell A1
Enter 15000 in Cell A1
In Cell B2, enter the formula "=Today() - 15000 + A1"
'------
Instead of Cell A1, you could use a cell located (out of sight) behind the spinner.

Jim Cone
San Francisco, USA

"gaftalik"
<[email protected]>
wrote in message

Hi all ,
In a cell which is B2 i have the following date 30-09-2005.Now how can
i assign a spinner to this date which is 38625 in order to increment 1
day at a time knowing that the spinner accepts maximum value as 30000?
Any smart solution ?
I dont know much about VBA but able to paste a code if someone can
explains .
Thank you very much .
 
Jim , your idea is so simple and great it worked perfectly, thank you
very much .

Re VBA code , i dont know much about VBA as well but anyway thank you
Pete for your time .
 
Per gaftalik:
I dont know much about VBA but able to paste a code if someone can
explains .

Here's something I use in MS Access. Dunno how
portable to Excel the code is though. In this
case, it's responding to Up/Down arrow keys.

I guess Excel has some sort of spin control,
but the idea would be the same
--------------------------------------------
Public Sub SpinDate(ByRef theTextBox As Control, ByRef theKeyCode As Integer,
ByVal theShiftStatus As Integer, ByVal theNumberOfDays As Long)
debugStackPush mModuleName & ": SpinDate"
On Error GoTo SpinDate_err

' PURPOSE: To increment/decrement date in the specified text box if user has
pressed
' one of the arrow keys AND if the control is enabled
' ACCEPTS: - Pointer to text box in question
' - Code of key pressed by user
' - Shift status of keyboard
' - Number of days to increment/decrement
' SETS: - Specified text box to a formatted date
' - KeyCode to zero if date changed, effectively swallowing the
keystroke
'
' NOTES: 1) Intended to be called from a date field's keyDown event.
' Code in the keyDown should look like this:
' +------------------------------------------------
' |
' | SpinDate Screen.ActiveControl, KeyCode, Shift, 1
' |
' +------------------------------------------------
' 2) We do not want to co-opt Alt/Ctrl key combinations because that
would
' effectively disable things like the user's pressing Alt+S to save
' or Alt+M to commit, hence the altDown/ctrlDown coding.

Dim altDown As Integer
Dim ctrlDown As Integer

altDown = (theShiftStatus And acAltMask)
ctrlDown = (theShiftStatus And acCtrlMask)

If (theTextBox.Locked = False) And (theTextBox.Enabled = True) Then
If (altDown = False) And (ctrlDown = False) Then
If theNumberOfDays = 30 Then 'Special case: taken to be request to move
by a full month
If IsDate(theTextBox.Value) Then
Select Case theKeyCode
Case vbKeyRight ', vbKeyUp ' We use KeyUp/Down for walking
the list
theTextBox.Value = DateAdd("m", 1, theTextBox.Value)
theKeyCode = 0

Case vbKeyLeft
theTextBox.Value = DateAdd("m", -1, theTextBox.Value)
theKeyCode = 0
End Select
Else
Select Case theKeyCode
Case vbKeyRight, vbKeyLeft ', vbKeyDown, vbKeyUp ' We
use KeyUp/Down for walking the list
theTextBox.Value = VBA.Format$(Date, "mm/dd/yyyy")
theKeyCode = 0
End Select
End If
Else
If IsDate(theTextBox.Value) Then
Select Case theKeyCode
Case vbKeyRight ', vbKeyUp ' We use KeyUp/Down for walking
the list
theTextBox.Value = DateAdd("d", theNumberOfDays,
theTextBox.Value)
theKeyCode = 0

Case vbKeyLeft
theTextBox.Value = DateAdd("d", -1 * theNumberOfDays,
theTextBox.Value)
theKeyCode = 0
End Select
Else
Select Case theKeyCode
Case vbKeyRight, vbKeyLeft ', vbKeyDown, vbKeyUp ' We
use KeyUp/Down for walking the list
theTextBox.Value = VBA.Format$(Date, "mm/dd/yyyy")
theKeyCode = 0
End Select
End If
End If
End If
End If

SpinDate_xit:
DebugStackPop
On Error Resume Next
Exit Sub

SpinDate_err:
BugAlert True, ""
Resume SpinDate_xit
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top