Setting Form focus based on current month

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to input data into 1 of 12 data boxes on a form based on the
current month. I am able to get a value 1-12 for the current month. What I
want to do is tell the form which specific data box to update the new data to
depending on the current month value

ex: current month = 5
The MayAccrue data box would then change from 0 to some new number.
Any ideas???
 
in message:
I am trying to input data into 1 of 12 data boxes on a form based on the
current month. I am able to get a value 1-12 for the current month. What I
want to do is tell the form which specific data box to update the new data to
depending on the current month value

ex: current month = 5
The MayAccrue data box would then change from 0 to some new number.
Any ideas???

Not sure where or how you want to launch this code, but here
is some generic code in the Form's Open event that will hopefully
get you going:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrorPoint

Dim intMonth As Integer

intMonth = DatePart("m", Date)

Select Case intMonth
Case 1
' Fill in January's box
Me.JanAccrue = 1
Case 2
' Fill in February's box
Me.FebAccrue = 2
Case 3
' Fill in March's box
Me.MarchAccrue = 3
Case 4
' Fill in April's box
Me.AprilAccrue = 4
Case 5
' Fill in May's box
Me.MayAccrue = 5
' etc, etc.
Case Else
' Nothing, ignore
End Select

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub
 
Back
Top