February 7th, 2007, 5:08 pm
Where's the wrong with the coding as below? I could not run it properly.Option ExplicitPrivate Sub btnCancel_Click() Unload Me EndEnd SubPrivate Sub btnOK_Click() Dim ctl As Control Dim ct As Control ' Make sure the data boxes have valid dates. For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Then If ctl.Value = "" Or Not IsDate(ctl) Then MsgBox "Enter valid dates in the text boxes.", _ vbInformation, "Invalid entry" ctl.SetFocus Exit Sub End If End If Next ' Capture the dates. firstDate = txtDate1 lastDate = txtDate2 ' Make sure the beginning date isn't after the ending date. If firstDate >= lastDate Then MsgBox "The beginning date should be before the ending date.", _ vbInformation, "Invalid dates" txtDate1.SetFocus Exit Sub End If 'Make sure the valid data are between 01/2003 and 12/2006. If firstDate < 1 / 2003 Or lastDate > 12 / 2006 Then MsgBox "The valid dates should be between 01/2003 and 12/2006.", _ vbInformation, "Invalid dates" ct.SetFocus Exit Sub End If Unload MeEnd SubPrivate Sub UserForm_Initialize() txtDate1 = "" txtDate2 = ""End Sub