80 likes | 146 Views
Active-X Calendar Control. 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
E N D
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
Code to preview report Private Sub cmdPrev_Click() Dim strRptName As String strRptName = "rptOrders" DoCmd.OpenReport strRptName, acViewPreview End Sub
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" calSelectDate.SetFocus Exit Sub End If ' check that value entered for end date If IsNull(txtEndDate) Then MsgBox "You must enter an ending date" cmdSetDate.Caption = "Set ending date" calSelectDate.SetFocus Exit Sub End If Include this code in Click Event handler for Preview and Print Buttons
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
Check whether form is open before running report Private Sub Report_Open(Cancel As Integer) IfNot 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 If End Sub
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 End If Next End Function