Use MsgBox to display the number of records imported

Posted on 2012-08-20
Last Modified: 2012-10-05

Hi Experts,

I have a module that imports invoice line item details from an Excel file.  At the completion of the import I would like to display the number of records successfully imported into a table named "Invoices".  I was using the ImportDate field to specify the records to count.  Here's what I was trying:

 'MsgBox DCount("*", "Invoices", "ImportDate = #" & Date & "#") & " records imported into Invoices table", vbInformation, "Import"

The MsgBox returns "0 records imported into Invoices table" which is incorrect. All records are being imported correctly.  Is someone able to help me with my syntax?  The full text of the module is attached in case anyone wishes to offer additional comments or improvements.  Thanks.
Question by:thutchinson
    LVL 75

    Accepted Solution

    Try brackets around the field name (?) Date, because Date is a Reserved Word ...

    MsgBox DCount("*", "Invoices", "ImportDate = #" & [Date] & "#") & " records imported into Invoices table", vbInformation, "Import"
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    Also, IF ... Date actually contains time (?), then try this:

    MsgBox DCount("*", "Invoices", "ImportDate = #" & DateValue([Date]) & "#") & " records imported into Invoices table", vbInformation, "Import"

    This assumes Date cannot be Null ...

    Author Comment

    Hi DatabaseMX.  

    Your suggestion didn't work.  In fact, now I don't get the Msgbox at all.  Instead the error trapping message kicks in and says it doesn't recognize a field (although all records were imported successfully.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now