Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    St. Charles, Illinois
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run command button (Access 2000)

    I have a button on the form that runs a command. However, I want the button to only run the command if the values in the subform are not null. Currently, if there are values - no problems. If there are no values I get an error message - run time error. What do you suggest.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run command button (Access 2000)

    What do you mean by "runs a command"? What is in the On Click event of the command button?
    (a) the name of a macro
    ([img]/forums/images/smilies/cool.gif[/img] [Event Procedure]
    an expression beginning with =

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    St. Charles, Illinois
    Posts
    222
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run command button (Access 2000)

    Its a do command that opens a report in preview mode.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run command button (Access 2000)

    You can insert code before the DoCmd.OpenReport line to check that the controls are populated. It would look like this (with other names, of course):

    Private Sub cmdOpenReport_Click()
    On Error GoTo ErrHandler

    If IsNull(Me.cboCustomer) Then
    MsgBox "Please select a customer.", vbExclamation
    Me.cboCustomer.SetFocus
    Exit Sub
    End If

    If IsNull(Me.txtAmount) Then
    MsgBox "Please enter an amount.", vbExclamation
    Me.txtAmount.SetFocus
    Exit Sub
    End If

    DoCmd.OpenReport "rptMyReport", acViewPreview
    Exit Sub

    ErrHandler:
    If Err <> 2501 Then
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run command button (Access 2000)

    In addition to Hans code, refer to


    http://www.mvps.org/access/forms/frm0031.htm


    Forms - Refer to Form and Subform properties and controls

    HTH, John

Posting Permissions

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