Results 1 to 2 of 2
  1. #1
    Marlene23 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    14

    Excel File Import Button on Form

    Good Day Everyone!

    I am a newbie to Access programming and after two days of searching finally found what I was looking for and management to get it to work but am now stuck with the next steps and are hoping that there might be someone that will be able to assist me with the relevant coding to add.

    I created a form with a button for front end users to be able to import an excel spreadsheet. The import works perfectly I do however need assistance with the following:

    1. Adding a message somewhere to say "Import Successful" - There is no way you know wether the file imported or not unless you go to the tables or look at the datasheet in the form.
    2. A way to stop importing duplicates - The same sheet can be imported multiple times and the data just keeps on adding to the existing data in the tables in other words there are duplicates.
    3. Delete the temp table that is created after every import - There is a table created "Name AutoCorrect Save Failures" every time a sheet is imported.

    I used the following coding:

    In a Module:

    Function selectFile()
    Dim fd As FileDialog, fileName As String

    On Error GoTo ErrorHandler

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    fd.AllowMultiSelect = False

    If fd.Show = True Then
    If fd.SelectedItems(1) <> vbNullString Then
    fileName = fd.SelectedItems(1)
    End If
    Else
    'Exit code if no file is selected
    End
    End If

    'Return Selected FileName
    selectFile = fileName

    Set fd = Nothing

    Exit Function

    ErrorHandler:
    Set fd = Nothing
    MsgBox "Error " & Err & ": " & Error(Err)

    End Function


    And the following code on my import button:

    Private Sub cmdImportNoDelete_Click()
    'Unset warnings
    DoCmd.SetWarnings False

    'Import spreadsheet
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "tbl_Mentors_Salaries", selectFile, True



    DoCmd.SetWarnings True
    End Sub


    Any assistance with the correct coding and where to insert it would be greatly appreciated!

    Thank you in advance!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    1. MsgBox at end of Sub

    2. Why are there duplicates? Is there a unique identifier field(s) that should be set to not allow duplicates?

    3. Why are there autocorrect failures? I have imported spreadsheets without this happening. DoCmd.DeleteObject
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2017, 01:34 AM
  2. Replies: 7
    Last Post: 10-24-2016, 01:55 AM
  3. Replies: 7
    Last Post: 06-30-2014, 12:11 AM
  4. Replies: 1
    Last Post: 04-20-2012, 07:20 AM
  5. create a button for import excel file
    By tggsun in forum Forms
    Replies: 3
    Last Post: 01-17-2012, 08:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums