Open Form Code

G

Guest

Right now I have a form with the following code:

-----------------------------------------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)

Dim strShowYear As String
Dim blnDone As Boolean

' Prompt the user for the year to be shown initially.
' We'll suggest next year as a default.
' In case of erroneous entry, continue prompting until
' a valid year is given, or the prompt is cancelled.

Do
strShowYear = InputBox( _
"What year do you want to edit?", _
"Enter Year", _
CStr(Year(Date) + 1))

Select Case True
Case (Len(strShowYear) = 0)
Cancel = True
blnDone = True

Case (Not IsNumeric(strShowYear)), _
(Val(strShowYear) < 1800), _
(Val(strShowYear) > 5000)
MsgBox "That's not a valid year!", _
vbExclamation, "Invalid Entry"

Case (Val(strShowYear) < (Year(Date) - 10)), _
(Val(strShowYear) > (Year(Date) + 10))
If MsgBox( _
"You entered " & strShowYear & _
", which seems odd. " & _
"Are you sure?", _
vbQuestion + vbYesNo, _
"Please Confirm") _
= vbYes _
Then
blnDone = True
End If

Case Else
blnDone = True

End Select

Loop Until blnDone

If Cancel <> True Then
Me.txtShowYear = strShowYear
Me.Requery
End If

End Su
-----------------------------------------------------------------------------------------------

This code was used to prompt the user of my form about what year they would
like to enter. Now I am making a form that will go by month and will need my
user to be prompted about the day, month and year they would like to enter.
My date is in short date format (1/1/2005). I have tried to change the code
myself, but I'm afraid I have no idea what I am doing. Please help!
 
N

Nikos Yannacopoulos

Tandy,

You could certainly do it in code, as I'm sure you could also reinvent
the wheel! Why bother? Use a pop-up form with a calendar control
instead, and some very simple code just to verify the selected date is
within range. Much simpler, much more user-friendly, and gives your app
a professional look.

HTH,
Nikos
 

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

Top