VBA import creates a blank row

godders199

New member
Local time
Today, 13:24
Joined
Oct 25, 2017
Messages
1
Hi, I am new to access, I have tried to follow instructions to set up a import VBA from excell, which does work, however for each line it imports , it creates a blank row at the bottom, for example 4 rows of data, will create 4 blank rows.
This is all the VBA i have written, copied guess somewhere it is going wrong.

Private Sub btnbrowse_Click()
Dim diag As Office.FileDialog
Dim item As Variant
Set diag = Application.FileDialog(msoFileDialogFilePicker)
diag.AllowMultiSelect = False
diag.Title = "please select an excel spreadsheet"
diag.Filters.Clear
diag.Filters.Add "excel spreadsheets", "*.xls,*.xlsx,*xlsm"
If diag.Show Then
For Each item In diag.SelectedItems
Me.Textfilename = item
Next
End If
End Sub

Private Sub importspreadsheet_Click()
Dim fso As New FileSystemObject
If fso.FileExists(Me.Textfilename) Then
Excelimport.importexcelspreadsheet Me.Textfilename, "allocation history"
End If

Public Sub importexcelspreadsheet()
Dim strexcelpath As String
strexcelpath = "S:\4th Floor\SQ Operations\OPs Mi Spreadsheets\Allocation audit tools\2018\history.xlsx"

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "Allocation history", strexcelpath, True, ""

Is anyone able to help me as currently all i know what to do is manually delete the rows after import which is not a long term solution.
 
There's nothing obviously wrong that I can see in your code
Have you checked whether your Excel files contain empty rows at the end?
The easiest way is to click Ctrl+End in the spreadsheet and see where it ends up.

A couple of other things:

For the 'newer' xlsx file format, you should use

Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12xml, "Allocation history", strexcelpath, True, ""

Is there anything else of relevance in that sub?
I ask as you didn't show it all...

Also try removing the Office. part in this line as its not needed
Code:
Dim diag As Office.FileDialog
 

Users who are viewing this thread

Back
Top Bottom