Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Sydney, New South Wales, Australia
    Thanked 0 Times in 0 Posts

    Opening Form Having No Data (2003 SP3)

    From a main data entry form I have a command button to view any historical data, if it exists. For such times, rather than opening to a blank screen showing the form header and footer only, is there a way to display a user friendly message, then return the user to the main form?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Opening Form Having No Data (2003 SP3)

    You can check in the On Open event of the form being opened:

    Private Sub Form_Open(Cancel As Integer)
    If Me.Recordset.RecordCount = 0 Then
    MsgBox "No records!", vbInformation
    Cancel = True
    End If
    End Sub

    You will have to ignore error 2501 in the On Click event procedure of the command button that opens the form. Here is some air code as example:

    Private Sub cmdHistory_Click()
    On Error GoTo ErrHandler
    DoCmd.OpenForm "frmHistory"
    Exit Sub

    ' Ignore error 2501 (form canceled)
    If Not Err = 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts