Page 4 of 5 FirstFirst 12345 LastLast
Results 46 to 60 of 66
  1. #46
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Quote Originally Posted by ItsMe View Post
    That's a good question. The code is specific to xlsx and even the Filepicker should filter to only that type. However, something is amiss. Perhaps to expand on making a new file, you could make a new CSV file and try importing that.

    AS for the link in the previous post, do not know why you would need to edit your registry or even consider it.

    Sorry it's been a while. Thanks so much for your help.



    My code is for a .xlsx file, it won't work if I choose another file type.
    I've tried importing my template .xlsx spreadsheet 2 times now into Access. Both have been met with the same F1, F2, etc error

    Here is my code:

    Code:
    Option Compare Database
    
    Sub Import()
    Dim strTable As String
    Dim strFilePath As String
    
    
    With Application.FileDialog(msoFileDialogFilePicker)
    
    
        .AllowMultiSelect = False
        .Title = "Locate a Excel file to Import"
        .ButtonName = "Import"
        .Filters.Clear
        .Filters.Add "Excel", "*.xlsx"
        .InitialFileName = "C:\Test"
        .InitialView = msoFileDialogViewThumbnail
        
            If .Show = 0 Then
            'There is a problem
            Exit Sub
            End If
        
        'Save the first file selected
        strFilePath = Trim(.SelectedItems(1))
        
    End With
    
    
    strTable = "tbl1_PartPricingDataAggregation"
    
    
    DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel12Xml, strTable, strFilePath, False, "A1:L1000"
    
    
    End Sub

  2. #47
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    any chance of getting an example excel file and/or database, I don't see a reason in the code to explain it basically duplicating entries on entirely different sets of fields.

  3. #48
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Could you give me your email address? I'm not sure if you'd be comfortable with that in a forum though. Is there a way you could delete the post after you receive the email from me?

    The files are too big to upload on here

  4. #49
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    the database doesn't need to be anything but the table that you're importing to and the form you're using as the interface, the rest of it is useless for the purposes of this question so you can just create a new database and import only those items necessary for the form to function correctly.

    After that you can zip up the database and the excel file to compress them.

    I've PM'd my email address to you

  5. #50
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    FYI

    I was able to reproduce the F1 error. I belive it has to do with multiple tabs in a workbook vs. single tab/worksheet.

    I was able to get the following to work with XLS. will test xlsx next.


    Code:
    Dim strTable As String
    Dim strFilePath As String
    
    With Application.FileDialog(msoFileDialogFilePicker)
    
        .AllowMultiSelect = False
        .Title = "Locate a Excel file to Import"
        .ButtonName = "Import"
        .Filters.Clear
    '    .Filters.Add "Excel", "*.xlsx"
        .Filters.Add "Excel", "*.xls"
        .InitialFileName = "C:\Test"
        .InitialView = msoFileDialogViewThumbnail
            If .Show = 0 Then
            'There is a problem
            Exit Sub
            End If
        'Save the first file selected
        strFilePath = Trim(.SelectedItems(1))
    End With
    
    'strTable = "tbl1_PartPricingDataAggregation"
    strTable = "tblTest"
    
    'DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel12Xml, strTable, strFilePath, False, "A1:L1000"
    DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel8, strTable, strFilePath, True

  6. #51
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    OK, two things. I do not see that the TransferSpreadsheet method supports xlsx. The latest version seems to be Office 12 which should be 2007 but I keep getting errors trying to export as xlsx. So I will guess this is where the problem lies.

    The second thing is that I provided the wrong Constant. Rather than acSpreadsheetTypeExcel12Xml should use acSpreadsheetTypeExcel12 or acSpreadsheetTypeExcel9

  7. #52
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Ok wow, great, so the template excel needs to be in .xls?

    Thanks so much, I'm going to try it out now!!

  8. #53
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Is there supposed to be a " ' " before the 2nd to last line of code you provided?
    'DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel12Xml, strTable, strFilePath, False, "A1:L1000"

  9. #54
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If the problem is multiple worksheets you probably want to modify your range

    "A1:L1000"

    To indicate the worksheet your range is referring to, the code will automatically assume you are importing from the first worksheet unless otherwise stated in your code.

    Thanks itsme! I didn't even think about wondering if it had multiple worksheets.

  10. #55
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    ...Funny that you mention that, since I'll have to duplicate this macro for all of the following tabs...hence why they're all in the same Excel
    How do you specify the spreadsheet in the code?

  11. #56
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Yah I did not extensively test importing XLSX. So the issue may, in fact, be "Range". I stopped testing at not being able to execute the following.
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "tblTest", "C:\Test\TestExport.xlsx", False

    It would error "Wrong Extension Type"

  12. #57
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    IT WORKED!!! You're brilliant!

  13. #58
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Well, I saved my file as Excel as .xls and it appended to my table/the table you created.

    But how can I specify the spreadsheet?

  14. #59
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Post #54 has the answer to that.

  15. #60
    Ace2014 is offline Advanced Beginner
    Windows XP Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    88
    Yeah, I don't know how to specify the spreadsheet though in code. I found this
    http://stackoverflow.com/questions/7...cess-using-vba

    I tried adapting my VBA myself, but I'm getting an error.

    Code:
    Sub Import()Dim strTable As String
    Dim strFilePath As String
    
    
    With Application.FileDialog(msoFileDialogFilePicker)
    
    
        .AllowMultiSelect = False
        .Title = "Locate a Excel file to Import"
        .ButtonName = "Import"
        .Filters.Clear
    '    .Filters.Add "Excel", "*.xlsx"
        .Filters.Add "Excel", "*.xls"
        .InitialFileName = "C:\Test"
        .InitialView = msoFileDialogViewThumbnail
            If .Show = 0 Then
            'There is a problem
            Exit Sub
            End If
        'Save the first file selected
        strFilePath = Trim(.SelectedItems(1))
    End With
    
    
    strTable = "tbl1_PartPricingDataAggregation"
    'strTable = "tblTest"
    
    
    'DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel12, strTable, strFilePath, False, "A1:L1000"
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable, strFilePath& '.tbl1a_Upload_Market_Data!', True,
    'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "tbl1_PartPricingDataAggregation", "C:\Test\TestExport.xlsx", False
    
    
    End Sub

Page 4 of 5 FirstFirst 12345 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 01-30-2014, 05:26 PM
  2. Replies: 11
    Last Post: 12-11-2013, 10:35 AM
  3. Automate Attendance
    By Palomino33 in forum Access
    Replies: 3
    Last Post: 01-14-2012, 03:57 PM
  4. Automate....
    By kusamharsha in forum Queries
    Replies: 3
    Last Post: 05-14-2009, 03:02 AM
  5. Replies: 1
    Last Post: 09-06-2006, 11:48 AM

Tags for this Thread

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