Solved

Stop import if certain criteria exists

Posted on 2015-01-17
3
218 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add records to a form to a table 11 41
FrontEnd tools to create web database application 7 61
Access: Retrieving Current Month's Orders for Invoice 6 29
Switch 5 17
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

810 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