How to Trigger "No Records Found" When There is No Records in .accde/.accdr?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Key
    New Member
    • Aug 2010
    • 132

    #1

    How to Trigger "No Records Found" When There is No Records in .accde/.accdr?

    Hi all once again!!!!
    I have a database in .accde/.accdr format. The database has been designed using many relational tables.
    I set a form for deleting some records or all database.
    The problem is when you delete the records with action query it pop-up a message saying "you about to delete zero rows (0s)from-specified table" ten times for 5-relational tables. It is very annoying!
    I know how to get read of this message and display a customer message as follows
    Code:
    Function messagebox()
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Do you for Real want to delete This Records ?"    ' Define message.
    Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
    Title = "Delete confirmations"    ' Define title.
           
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then    ' User chose Yes.
    DoCmd.OpenQuery "DeleteMytableName", acViewNormal
    DoCmd.RunMacro "Confirmation"
    Else    ' User chose No.
    Doc.RunMacro "Cancel"
    End If
    End Function
    It runs perfectly with DoCmd.RunMacro "Confirmati on" as messagebox macro for confirmation and
    Doc.RunMacro "Cancel" for cancellation.
    The problem with this, once you select the record to delete, it keep deleting without giving any indication that there is no records in the database.
    How to set the code above to search for presence/absence of records first before attempting to delete empty table regarding the following criteria???
    1. If no records, then NO RECORDS FOUND message should be displayed without taking any further actions
    2. If there are records on the related table then it should delete it with warnings as explained above

    Happy X-Mas and New Year!!!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    I suggest you open the record source (Table or Query) you want to delete from using a DAO.Recordset object and check for EOF. If EOF is already true then there are no records.

    If the record source is either a table or a QueryDef (Not SQL), then you can use DCount() of it to determine if there are any records or not.

    Comment

    Working...