Presentation is loading. Please wait.

Presentation is loading. Please wait.

Active-X Calendar Control

Similar presentations


Presentation on theme: "Active-X Calendar Control"— Presentation transcript:

1 Active-X Calendar Control

2 Code to set dates Private Sub Form_Open(Cancel As Integer)
' set button caption when form opens cmdSetDate.Caption = "Set beginning date“ End Sub Private Sub cmdSetDate_Click() If cmdSetDate.Caption = "Set beginning date" Then txtBeginDate = calSelectDate.Value cmdSetDate.Caption = "Set ending date" Else txtEndDate = calSelectDate.Value cmdSetDate.Caption = "Set beginning date" End If End Sub

3 Code to preview report Private Sub cmdPrev_Click()
Dim strRptName As String strRptName = "rptOrders" DoCmd.OpenReport strRptName, acViewPreview End Sub

4 Check for valid date entry
' check that end date is > begin date If txtEndDate < txtBeginDate Then MsgBox "The ending date must be later than the beginning date" cmdSetDate.Caption = "Set ending date" calSelectDate.SetFocus Exit Sub End If ' check that value entered for begin date If IsNull(txtBeginDate) Then MsgBox "You must enter a beginning date" cmdSetDate.Caption = "Set beginning date" ' check that value entered for end date If IsNull(txtEndDate) Then MsgBox "You must enter an ending date" Include this code in Click Event handler for Preview and Print Buttons

5 Report No Data Event Private Sub Report_NoData(Cancel As Integer) Cancel = MsgBox("No orders to display in range specified. Cancelling report...", _ vbInformation, _ Me.Caption) End Sub

6 Check whether form is open before running report
Private Sub Report_Open(Cancel As Integer) If Not FormIsloaded("frmPrintOrders") Then Cancel = MsgBox("To preview or print this report you need to select dates from the Print Orders form. Open form?", vbOKCancel, Me.Caption) If Cancel = vbOK Then DoCmd.OpenForm "frmPrintOrders" End If End Sub

7 FormIsLoaded function
Public Function FormIsloaded(strFrmName As String) As Boolean Const conFormDesign = 0 Dim intI As Integer FormIsloaded = False For intI = 0 To Forms.Count - 1 If Forms(intI).FormName = strFrmName Then If Forms(intI).CurrentView <> conFormDesign Then FormIsloaded = True Exit Function End If Next End Function


Download ppt "Active-X Calendar Control"

Similar presentations


Ads by Google