Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I stop this message from being displayed? 1

Status
Not open for further replies.

justme1310

Technical User
Jul 23, 2003
16
TT
Hello everyone,

I have the following code that checks for instances when no matching records are found.

When it happens, in addition to getting my "no records found" msg, I also get this message "The Openform Action was cancelled".
Is there anyway to stop this msg from being displayed??


Code:
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
  MsgBox "Sorry!!!  No records found!"
    Cancel = True
Else
    CurRonc = ROncologist
    CurMonc = MOncologist
End If

End Sub


Many thanks in advance


Will
 
How are you "opening" the form? From a command button on another form? If so, you could use that button to do the check for existing records. If records are not found, provide the error message and don't call the open of this form. If records are found, call the open of this form and then you only need what is now in the Else part above in you open statement becuase you have already done that checking.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
the reason that you get a message is that the cancel event is counted as an error.

you can avoid this error completely by doing what mstrmage1768 suggested and move the record checking out of the form's event, or you could handle this error by ignoring it with error handling techniques...

--------------------
Procrastinate Now!
 
Hi Robert,

Thanks for responding so quickly.

The form is based on a query that has an "enter parameter value" dialog box which asks for the record number.

The form itself is opened by clicking on a command button.

The following is the code in the on click event of the command button.

Code:
On Error GoTo Err_Command2_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmchangeOncologist"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command2_Click:
    Exit Sub

Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    
End Sub

Where exactly should I put the code to check for existing records?


Many thanks


Will
 
Well, you first have to figure out how to check for existing records. Do you know how to check that? If not, what is the SQL for the query that feeds frmchangeOncologist?

Once you have that part solved, the above code would become something like:

Code:
On Error GoTo Err_Command2_Click

    ' all the record existance checking code goes here

    If NoRecords Then
        MsgBox "Sorry!!!  No records found!"
    Else
        Dim stDocName As String
        Dim stLinkCriteria As String

        stDocName = "frmchangeOncologist"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    End If

Exit_Command2_Click:
    Exit Sub

Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    
End Sub

And the Form_Open event of the frmchangeOncologist you originally posted would become:

Code:
Private Sub Form_Open(Cancel As Integer)

    CurRonc = ROncologist
    CurMonc = MOncologist

End Sub

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
have you tried to just have docmd.close instead of the cancel = true?

--------------------
Procrastinate Now!
 
Robert,

To check for records I would use this code in the open form event

Code:
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
  MsgBox "Sorry!!!  No records found!"
    Cancel = True
End If

End Sub

The SQL for the query that the form is based upon is as folows:-


Code:
SELECT tblPerson.*, tblAtdocts.*
FROM tblPerson LEFT JOIN tblAtdocts ON tblPerson.FILENO = tblAtdocts.FILENO
WHERE (((tblPerson.FILENO)=[Please Enter Patient File No]));


Thanks

Will
 
Hi Crowley,

I tried the DoCmd.Close as you suggested and it works great.


Thanks again Robert for your help

Thanks so much.
Will

 
Glad to hear Crowley helped you out [smile]

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top