Solved

Stop import if certain criteria exists

Posted on 2015-01-17
3
222 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 500 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 57
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

733 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