?
Solved

Stop import if certain criteria exists

Posted on 2015-01-17
3
Medium Priority
?
228 Views
Last Modified: 2015-01-17
I have the following code which executes a saved import.

Private Sub cmdImportData_Click()


    If MsgBox("This function will import the named range of your Excel file and append the data table.  You must be sure to do this only one time for each new Excel file.  Do you wish to continue??", vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
        DoCmd.RunSavedImportExport "ImportData"
        MsgBox "The data from the Excel file has successfully been imported."
    Else
        Exit Sub
    End If

End Sub

Open in new window


But if a record, or row in the Excel file, containing for example "5/8/2011" in a field named "Week starting date" in the Excel file and in the resulting Access table already exists I do not want that record to be imported.

How can I do this?

--Steve
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40555191
if that is the case, you have to import the excel file into a temp table, then create an append query like this

insert into FinalTable
select tempTable.*
from temptable left join FinalTable on temptable.[fieldname]=FinalTable.[fieldname]
where FinalTable.[fieldname] is null
0
 
LVL 58
ID: 40555197
Or use OLE automation to control Excel directly and do the import.

 I would use Rey's approach however as it's far simpler.   But I thought I'd mention it for future reference in case you find your needs getting a little more complex.

Jim.
0
 

Author Closing Comment

by:SteveL13
ID: 40555220
Rey,  That suggestion works perfectly.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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