Run time error 2501 open form action was cancelled Results

I have a database created by access 2003, this database is in share folder but now for some user a popup message is appearing (Run-time error '2501': The OpenForm action was cancelled).

This error is only appear for some user which they could not open some forms in the database.

In the same PC when other staff try to login to PC then access the database with same username it work fine for them.

Can somebody help me resolving this matter.

Hi all,

Im new to this forum, but i need some desperate help.

I was assisting a friend who's PC crashed...(Motherboard). Any way he runs Physiotherapy business and had an access application which keeps record of his clients and other transactions. I plugged the HDD into another PC and retrieved the folder which holds the access DB and any other associated files.

Now to the problem... When he opens the access database all seems to work, however on one of the forms (The most important i might add) he recieves a Run Time Error 2501:The OpenForm Action was canceled.

When i debug it points me to the
DoCmd.openForm "frmPatientRecordsExisting" (Attached Image)

I looked at the code but im no programmer so i really would appreciate some help.
I have attached the code of frmPatientRecordsExisting form

Everything else seems to work fine and i cant get my head around it. I have checked the references and they all seem fine. Again I am not an Access programmer so my knowledge is limited..

I really appreciate any help


I have a custom dialog box which has combo boxes to choose criteria for a query and then exports the query to Excel. The problem comes if the user gets to the 'Output To' save box but then decides to cancel I/they get Run-Time Error '2501': The OutputTo Action was cancelled which then stops the procedure and efefctively for the end user breaks the database and scares the hell out of them! Is there some code I can add that will either stop them cancelling or alternativel, and preferably for VBA to just ignore it and cancel the whole action, closing the dialog box(as it is supposed to once saved) Code shown below:

	Private Sub cmdOKRepHQAll_Click()
If IsNull(cboREPAll) Then
      MsgBox "You must choose a Rep." _
         & vbCrLf & "Please try again.", vbExclamation, _
         "More information required."
      Exit Sub
 End If
 ' Open MsgBox to tell user that a save box will open next
    MsgBox "Please Rename and Save The Export", vbQuestion, "Export To Excel"
    ' Exports Query to Excel
    DoCmd.OutputTo acOutputQuery, "qryByRep", "ExcelWorkbook(*.xlsx)", "", True, "", 0, acExportQualityPrint
    ' Closes Form
    DoCmd.Close acForm, "frmChAllbyRep"
End Sub

I have a report filtered by date (between 2 dates). I put the following NoData event:

	Private Sub Report_NoData(Cancel As Integer)
' Display a message if user enters a date for which there are no records,
' and don't preview or print report.
    Dim strMsg As String, strTitle As String
    Dim intStyle As Integer
    strMsg = "There is no records!"
    intStyle = vbOKOnly
    strTitle = "No Data for Date Range"
    MsgBox strMsg, intStyle, strTitle
    Cancel = True
End Sub

I have created a Switchboard (with the Switchboard Manager) to open the report.
If there is no records between the 2 dates, the messagebox (with the "There is no records" message) is activated, and after that I get "Run-time error '2501': The OpenReport action was cancelled" error message.
There is the code using for the switchboard:

Quote: Option Compare Database
Option Explicit

Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.
' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub

Private Sub Form_Current()
' Update the caption and fill in the list of options.
Me.Caption = Nz(Me![ItemText], "")
Me.lblLabel.Caption = Nz(Me![ItemText], "")

End Sub

Private Sub FillOptions()
' Fill in the options for this switchboard page.
' The number of buttons on the form.
Const conNumButtons = 8

Dim con As Object
Dim rs As Object
Dim stSql As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the focus.
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard page"
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
End If
' Close the recordset and the database.
Set rs = Nothing
Set con = Nothing
End Sub

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.
' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8
Const conCmdOpenPage = 9
' An error that is special cased.
Const conErrDoCmdCancelled = 2501

Dim con As Object
Dim rs As Object
Dim stSql As String
On Error GoTo HandleButtonClick_Err
' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [Switchboard Items] "
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND [ItemNumber]=" & intBtn
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If no item matches, report the error and exit the function.
If (rs.EOF) Then
MsgBox "There was an error reading the Switchboard Items table."
Set rs = Nothing
Set con = Nothing
Exit Function
End If

'If Not (conCmdOpenReport) Then
' Exit Function
'End If

Select Case rs![Command]

' Go to another switchboard.
Case conCmdGotoSwitchboard
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]

' Open a form in Add mode.
Case conCmdOpenFormAdd
DoCmd.OpenForm rs![Argument], , , , acAdd
' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rs![Argument]
' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rs![Argument], acPreview
' Customize the Switchboard.
Case conCmdCustomizeSwitchboard
' Handle the case where the Switchboard Manager
' is not installed (e.g. Minimal Install).
On Error Resume Next
Application.Run "ACWZMAIN.sbm_Entry"
If (Err 0) Then MsgBox "Command not available."
On Error GoTo 0
' Update the form.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.Caption = Nz(Me![ItemText], "")
' Exit the application.
Case conCmdExitApplication
' Run a macro.
Case conCmdRunMacro
DoCmd.RunMacro rs![Argument]
' Run code.
Case conCmdRunCode
Application.Run rs![Argument]
' Open a Data Access Page
Case conCmdOpenPage
DoCmd.OpenDataAccessPage rs![Argument]
' Any other command is unrecognized.
Case Else
MsgBox "Unknown option."

End Select
' Close the recordset and the database.

On Error Resume Next
Set rs = Nothing
Set con = Nothing
Exit Function
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.

If (Err = conErrDoCmdCancelled) Then
Resume Next
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

End Function When I debug, the line of the code that I have in bold typeface is the line that is highlighted.

I have been at it for a while but I cannot figure out what is wrong. Please help.

Thanks in advance.

Okay, so here's a monument to my naivety with SQL.

What I'm trying to do is a little complicated, but I'll try my best to explain.

Upon filling in an ID number in a form, I want two pieces of data to automatically update: The Part Name associated with given ID, and the quantity remaining for the ID.

The only way I know how to do this is, while the main form is open (let's call it form A), open a different form (let's call it Form B) that displays the data, set the value on Form A, and close form B. (I tried just doing the set value by itself, but the form displaying the data I want the value set to needs to be open.)

I have some code in the "On Lost Focus" event of the ID field so that after the ID field is updated, the Part name and Quantity remaining for that ID are updated. If the ID doesn't exist in the INBOUNDS table, a message box pops up stating that, and if the ID field is left blank, it doesn't do anything.

If the ID field IS filled in with a valid ID, what I want it to do is open up 2 forms, one that figures out the Part name of the ID in the ID field, and one that calculates the total quantity remaining.

Here is what I have.

	Private Sub ID_LostFocus()
    If IsNull([ID]) Then
        Exit Sub
    End If
    If Not IsNull([ID]) Then
        If DCount("*", "INBOUNDS", "[ID]=Forms![OUTBOUND NEW]![ID]") < 1 Then
            MsgBox "There is no record for this ID!"
            Exit Sub
            DoCmd.OpenForm "OUTBOUNDS ID 2 PART", , , , , acHidden
            [Forms]![OUTBOUND NEW]![PART] = [Forms]![OUTBOUNDS ID 2 PART]![PART]
            DoCmd.Close acForm, "OUTBOUNDS ID 2 PART", acSaveNo
            DoCmd.OpenForm "LEFTbyIDout", , , , , acHidden
            [Forms]![OUTBOUND NEW]![QTY REM] = [Forms]![LEFTbyIDout]![QTY]
            DoCmd.Close acForm, "LEFTbyIDout", acSaveNo 
       End If
    End If
End Sub

Ok, before anyone comments, I DO know that it's bad form to have spaces in names... I'm working on it. For now, though, this is what I've got, and I'm very careful to bracket anything with spaces.

Ok, moving on. For whatever reason, this is either giving me an error and/or shutting down Access. I HAVE narrowed it down to this code. In fact, if I take out the code in bold purple, it works just fine.

So, two questions.

First of all, is there a better way to do this?

And secondly, if not, why is my code crashing Access?


I just realized I didn't put up the error message, but I also just realized something else, too.

I get this error message:

Quote: Run-Time error '2501'.

The OpenForm action was cancelled. But the weird thing is, it still updates the Quantity Remaining field on the main form, as if the LEFTbyIDout form had been opened with no problem. The Continue button is grayed out, but the End, Debug, and Help buttons are clickable.

I'm running office 2000 with A2K
I have a button on my form that when pressed takes some info from the form and places it in the body of an email. Everything works fine if the user does what they are supposed to...but we all know we can't count on that.

When outlook opens and the user decides they don't want to send an email after all and just closes outlook, this error pops up... "Run Time Error 2501 The SendObject Action was cancelled" then there's END and DEBUG.

I do not want the user to be able to hit DEBUG and get into my code. Here's my code:

Private Sub cmdEmail_Click()
MsgBox "Please be patient this will take a minute", vbInformation, "Be Patient"
DoCmd.SendObject , , , , , , "Trouble Ticket", _
"Ticket Date: " & Me.TicketDate & vbCrLf & "User: " & Me.UserFirstName & vbCrLf & _
"Problem Description: " & Me.ProblemDescription, False
End Sub

I've tried using if err.code = 2501
On err goto
and others, I don't think I have the syntax or order right though.

Any ideas? Thanks!


This is a pretty basic question i just dont know where to begin looking. I have a form with buttons which open reports. I have each report set up to 'Between [startDate] And [endDate]' so when opening the report the user is prompted to enter dates. If you choose cancel I get a Run-time error 2501: The OpenReport action was canceled. How can i go about leaving this error out of the picture? Or even better, if i user decides to cancel it just pulls ALL data, not just from a specified date.
Thanks in advance

**EDIT- I dont know if there are other ways of doing this, but i would like to do this in VBA******

I get error 2501 when I cancel the report.

How do I go about this error?

When cancel is clicked, can it just resume and maybe just open a form?

The following code was generated by a wizard when creating a button that is meant to open a form:

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Data Entry"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit Sub

MsgBox Err.Description
Resume Exit_Command10_Click
End Sub

The above code however will always give run time error 2501 ‘The open form action was canceled – you used a method of the docmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.’

Well the above isn’t true the new form opens I click the DataEntry button and then I get the above message.
Wud appreciate any thoughts.

Hi all,

I have a frm (frmmain) that holds a subfrm (subControlIN_table) in wich incoming messages (correspondence about projects) are stored. To retrieve a message I click on the record selector and a new form (frmIN) opens that displays the message and further details. This works fine. A problem arrises when I'm trying to add a new correspondence record in the subform. I've made a button on frmmain with this code behind it:

Private Sub btnAddIN_Click()
Dim StrMsg As String
Dim intRespons As Integer
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMain"

StrMsg = "You are about to add a Received Message to the project: " & vbNewLine & " " & vbNewLine & Me!WorkingTitle & " " & vbNewLine
StrMsg = StrMsg & " " & vbNewLine & "Continue?"

intRespons = MsgBox(StrMsg, vbInformation + vbYesNo + vbDefaultButton2, "Store received message for this Project")

If intRespons = vbNo Then
DoCmd.RunCommand acCmdClose
Exit Sub
End If

If intRespons = vbYes Then
stDocName = "frmIN"
stLinkCriteria = "[ProjectID]=" & "'" & Me![ProjectID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
End If

With Forms!frmIN
.WorkingTitle = Me.WorkingTitle
.SFNumber = Me.SFNumber
.ProjectID = Me.ProjectID
End With

End Sub

I expected this to open a blanc record of frmIN but it doesn't. I cannot find the mistake. I get this error message: Run-Time error 2501 the OpenForm action was cancelled. In the code page this line is high-lighted: DoCmd.OpenForm stDocName, , , stLinkCriteria

So I suppose that's where the problem lies, but could be wrong?
Help would be appreciated.


I have some email fields set up in a form so that the user can click on an address and have it automatically open up outlook and fill in the "To:" field. Everything works fine, except if you decide not to sent the message and close outlook, I get the following visual basic error:

Run-time error '2501':

The SendObject action was canceled.

Instead of this popping up and opening visual basic, I'd like to have a simple message box pop up that says "the send object action was canceled" and the user can just hit "ok" and it takes them back to the form, instead of launching VB.

In another form I have an option to email a report, and when I hit the X on that one, it just gives a simple error message and returns the user back to the form. I've compared the code for both, and I can't see any difference.

Any help is greatly appreciated!


I have created a form that accepts input via a text box( txtfilter) and command button (cmdsearch).
The inputed term is used to search all fields in my table (parts) and the results of the search are displayed in a list box (lstresults)
When a result in the list box is clicked on it should display the record on a new form.

My problem – When a result is clicked on I receive the following error and the form does not open.

Run-time error 2501
"The openform action was cancelled"

Can anyone tell me if I have messed up the syntax on my “Docmd.openform” ?


My code:

Private Sub cmdSearch_Click()
If IsNull(Me.txtfilter) Then
MsgBox "You have not entered any text.", vbExclamation, "Attention"
Exit Sub
End If
.RowSource = "Select * FROM parts WHERE ((([part no]) Like '*" & Me.txtfilter & "*') OR (([description]) Like '*" & Me.txtfilter & "*') OR (([bin location]) Like '*" & Me.txtfilter & "*')OR (([in stock]) Like '*" & Me.txtfilter & "*')OR (([price 1]) Like '*" & Me.txtfilter & "*')OR (([price 2]) Like '*" & Me.txtfilter & "*')OR (([price 3]) Like '*" & Me.txtfilter & "*') );"

End With
End Sub

Private Sub Command54_Click()

End Sub

Private Sub Form_AfterUpdate()

End Sub

Private Sub lstResults_AfterUpdate()
DoCmd.OpenForm "parts", acNormal, , "[part no] = " & LSTRESULTS.Column(0)

End Sub

Private Sub Close_search_form_Click()
On Error GoTo Err_Close_search_form_Click


Exit Sub

MsgBox Err.Description
Resume Exit_Close_search_form_Click

End Sub
Private Sub List70_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[part no] = " & Str(Nz(Me![List70], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

I have a form that works perfectly fine on its own, but for some reason when it is embedded in my navigation form I get a strange popup. Here's a basic description of how things should function (and do on their own):

frmJudgeType contains combo box with three choices and an OK button
user makes selection in combo box, hits OK and runs qryJudgeType which produces rptJudgeType

When the form is used within the Navigation Form, however, clicking OK produces a popup that reads:

Enter Parameter Value:
(below this is a textbox and OK/Cancel buttons)

This line is set as the criteria in qryJudgeType under one of my columns - cboJudgeType points to my OK button on frmJudgeType. But like I said, this doesn't appear at all when the frmJudgeType is ran on its own outside of the Navigation form.

If I hit cancel on the Parameter Value popup, I get an error message that reads:

Run-time error '2501':
The OpenReport action was canceled.

If I hit debug, Visual Basic appears shows my code to run the OK button, which reads:

Private Sub cmdOK_Click()
DoCmd.OpenReport "rptJudgeType", acViewReport

Hi, I'm inserting a report based on the current open record into Outlook email. It all works fine except for a couple of things. If the email is cancelled, an error displays along with the report being left open - due to debugging. (Run-time error '2501': The SendObject action was cancelled). What code can be written to allow the completion if user cancels email (giving message saying, 'Action Cancelled by User' and then closing open report - just as if it was completed sucessfully)?

Private Sub Command25_Click()
Me.Dirty = False
DoCmd.OpenReport "nonconformity", acViewPreview, , "[nonconformid] =" & Me.NonConformID
DoCmd.SendObject acSendReport, , acFormatPDF, Forms![non conformity]![Contact] DoCmd.Close acReport, "NonConformity", acSaveNo
End Sub

Thanks in advance

I have a button on a form, when clicked opens another form based on a query.

If you press the Escape Key while this query is running it comes up with:

"Run-Time error '2501'"

The OpenForm action was canceled.

Debug takes me to:

DoCmd.OpenForm "frmInfoPull", acNormal

So I need something that if someone presses the Escape Key, while this query is running, it simply stops the query.

Thanks for the resonces from the original post however I have already done what was suggested. Let me explain again. I created a form called frmDateRange to search a date range specified by the user and display this chosen range on a report (rptDateRange). All the user has to do is enter the beginning and ending dates and click on the Ok button. Behind the Ok button is this code:

Private Sub cmdOk_Click()

If IsNull(Me.txtStartDate) Or IsNull(Me.txtEndDate) Then
MsgBox "Both dates are required for this search!", vbInformation

DoCmd.OpenReport "rptDateRange", acViewPreview, , _
"[RequestDate] Between #" & Format(Me.txtStartDate, "mm/dd/yyyy") _
& "# And #" & Format(Me.txtEndDate, "mm/dd/yyyy") & "#"
DoCmd.close acForm, Me.Name

End If

End Sub

This will open the report just fine. However if there is no data to display I would like a message box to appear and tell the user there is no data to show and then close the report. I tried this by going to the Reports No_Data and entering this code:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Records found for this Date Range." & vbNewLine & _
"Report will now close. Please try another.", vbInformation
Cancel = True
End Sub

When I do this I get this Error:

Run-time error '2501':
The OpenReport action was canceled.
You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that askes if you want to save the changes you made to the form.

Then it highlights the Else: code in my frmDateRange. I understand what the error is saying, but I don't know how to get around it. Thanks in advance.

hi guys, here is the situation.

I have 3 forms:
1- editpopsubform where the info comes from a select statement.

2- editPoplist , which has the form 1 as a subform

3- editpop, a form which allows the user to edit a record selected in the poplist form.

The idea is to open the editpoplist form, where a list of records appears. Once a record is double clicking in the code number, the editpop form is open showing all the details for that particular record.

the code number in the editpop from is assigned as per the following:


Problem: when i double click in the code number the following error appears...

"run-time error 2501 . the open form action was cancelled"

any clue?
thx max.

I am having great frustration and am hoping someone can help. I work at a college and in our admissions database is a button that allow on click to open the Potential Students Form. That worked great until today - on that form was a value list that I changed to a table/query. After I made that change, when you were on the main menu and clicked on the View Potential Students button is displayed an error message that read "Run-Time Error '3615' Type mismatch in expression." I have no idea that this means. So I went and changed the table/query back to a value list - well now when you click on the view potential students a box appears that says "Lookup_Interest.Interest" and it wants me to enter something - all I want is the View Potential Students button to open that form and then the Interest to be a pulldown menu that allows to select from the linked table. When I cancel the Lookup box another "RunTime Error '2501' The OpenForm action was canceled. " Then the DeBug takes me to the command (which is correct) DoCmd.Open Form "PotentialStudents"
Any ideas???????

I have 2 forms

One is a copy of the other, the copy differs in it has some modifications in it.

The button that calls the copy form gives an openForm action cancelled message(something very similar to run time error 2501 ‘The open form action was canceled – you used a method of the docmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box.’)

When I compile the code of the copy form I get this message which highlights a PRIVATE procedure.
‘Compile error: member already exists in a object module from which this object module derives.’

So basically it’s referencing the procedure as it occurs in the original form, but I don’t want it to do that, I want the call statement to access the procedure in the current form, which happens to be the copy form.

Is my thinking off in that you can’t call a procedure in one class from another class, esp. if the called procedure is private?

When I comment out my procedure in my copied form, the copy form begins running fine, but the procedure returns incorrect values in my control and this is what I want to avoid.

NEW: the command (next, prev record) buttons don't seem to be the issue. they were commented out and the form still won't Open from the menu OR manually.

WHEN I try to manually run the form i get a message that basically says:

The expression on open as the event property setting produced the following error: Procedure Declaration does not match description of event or procedure having the same name.

there is a main menu that has a cmd button "edit or del records". when i click that button I get the error msg above.

the on open event has one line that says "DoCmd.OpenForm ("Edit")

this worked before, there is a form called Edit, spelled exactly that way. I know you don't always get the statement causing the error all the time, but this is stupid or I did something stupid that I forgot about.
Please look at the code and see what's what? I can't fig it out.

trying to use an edit form that has worked fine with docmd.openform("Edit")

until I realized that the end user won't be looking at the current record or BOF or EOF.

i understand the error message that comes up, but she won't and she will panic. besides, if i can write code to prevent that from happening that is what should be done anyway.

after adding the code below, every time i try to open the form, access gives me the aforementioned error and says the openform action was cancelled. this is the only thing i added, so i need to know if i did something stupid and that is causing the problem??

PS: The form won't open manually or via the code. It keeps saying the on open event "did not resolve" to a vba event or some control and that i need to check spelling. I cannot find anything wrong.

Private Sub NextRecBtn_Click()
Dim currentrec, lastrec As Long, numrows As Integer

numrows = DCount("*", "EQPT")
lastrec = numrows
currentrec = frm.CurrentRecord (should be current rec in EQPT table)

If numrows = 1 Then

Me.NextRecBtn.Enabled = False
ElseIf currentrec = numrows Then

Me.NextRecBtn.Enabled = False

Me.NextRecBtn.Enabled = True
DoCmd.RunCommand acCmdRecordsGoToNext
End If
End Sub

All i want to do is to enable/disable the next and previous record command buttons at the appropriate times. my logic is that if the current record is the last record, then disable the next record button. also, if the current record is record 1, disable the previous record button, and if neither condition is true enable both buttons.

Not finding an answer? Try a Google search.