Convidad 29/7/2011, 15:35
Private Function fctnDate_Click(ctl As Control)
' Called by clicking any date on the calendar grid
Dim datOut As Date ' Date variable to be retained after frmCalendar is closed
If ctl.ForeColor = 0 Then ' In the currently displayed month, i.e. date not greyed out
datOut = CDate(ctl.Caption & " " & labDat.Caption) ' Set datOut
Else
If CInt(Mid$(ctl.Name, 4)) < 8 Then ' Tail-end of the previous month
datOut = CDate(ctl.Caption & " " & Format(CDate(Format(labDat.Caption, "dd-mmm-yyyy")) - 1, "mmmm yyyy")) ' Set datOut
Else ' Start of the next month
datOut = CDate(ctl.Caption & " " & Format(CDate(Format(labDat.Caption, "dd-mmm-yyyy")) + 31, "mmmm yyyy")) ' Set datOut
End If
End If
If datOut > Date Then
MsgBox "Data não pode ser superior a Hoje...", vbCritical
Exit Function
Else
DoCmd.Close acForm, "frmCalendar", acSaveNo ' Close frmCalendar first, as it's modal
ctlIn = datOut
End If
End Function