davidjearly
Registered User.
- Local time
- Today, 12:10
- Joined
- Apr 30, 2009
- Messages
- 40
Hi,
I am trying to append the data I have stored in Excel format into an Access table using the following code:
The table and excel file have the same column structure, but when I import the records, hundreds of blank rows are being randomly inserted between the records.
Any ideas?
Thanks!
I am trying to append the data I have stored in Excel format into an Access table using the following code:
Code:
Private Sub Command0_Click()
If MsgBox("This will open the Excel folder for spreadsheet imports. Continue?", vbYesNoCancel) = vbYes Then
Dim i As Integer
Dim tblStr As String
Dim varItem As Variant
i = 1
tblStr = "Patients"
With Application.FileDialog(msoFileDialogFilePicker)
With .Filters
.Clear
.Add "All Files", "*.*"
End With
.AllowMultiSelect = True
.InitialFileName = "c:\"
.InitialView = msoFileDialogViewDetails
If .Show Then
For Each varItem In .SelectedItems
For i = 1 To Len(varItem)
If IsNumeric(Mid(CStr(varItem), i, 1)) Then
tblStr = tblStr & Mid(CStr(varItem), i, 1)
End If
Next i
If Right(CStr(varItem), 4) = ".xls" Then
DoCmd.TransferSpreadsheet acImport, , tblStr, CStr(varItem), True
i = i + 1
DoCmd.OpenTable tblStr, acViewNormal, acReadOnly
MsgBox "Data Transferred Successfully!"
DoCmd.Close
tblStr = ""
End If
Next varItem
DoCmd.Close
End If
End With
End If
End Sub
The table and excel file have the same column structure, but when I import the records, hundreds of blank rows are being randomly inserted between the records.
Any ideas?
Thanks!