Armitage2k
Registered User.
- Local time
- Tomorrow, 06:52
- Joined
- Oct 10, 2009
- Messages
- 34
Hello!
I am using the following code to import data from a closed XL spreadsheet and import it into a table in my database.
the problem with the code is that it imports from the .xls as wished, but it creates me around 300 empty entries before showing me the first entry which is entered in row 2 on the xl spreadsheet.
Solution to this would be a way to check for empty fields and if yes, delete the whole line. (Eg. if field "Profile ID" is empty, delete whole line)
Further, I later want to import the data directly into an existing table, but i would need Access to understand that if the entry in the field "Profile ID" exists already, that it shall replace the existing one. However, no double existing entries may exist in the database (measured by the Profile ID).
Maybe someone can give me a hand on this since I dont know how to do this, respectively where to start.
Thanks for the help!
A2k
I am using the following code to import data from a closed XL spreadsheet and import it into a table in my database.
Code:
Sub GetDataFromClosedWorkbook()
Dim wb As Workbook
Dim ws As Worksheet
Dim db As Database, rec As Recordset
Dim Filename As Object
Dim Selection As String
Set db = CurrentDb
Set rec = db.OpenRecordset("VIP")
Set Filename = Application.FileDialog(msoFileDialogFilePicker)
With Filename
.InitialView = msoFileDialogViewDetails:
.InitialFileName = "C:\test\":
.Filters.Clear:
.Filters.Add "Pick .xls File", "*.xls", 1:
.ButtonName = "Import file":
.Title = "Search for Database_Import.xls file"
' If no file is selected, close the sub, else keep going
If .Show = -1 Then
Selection = .SelectedItems(1)
Else:
Exit Sub
End If
End With
Set wb = Workbooks.Open(Selection, True, True)
Set ws = wb.Worksheets("VIP") ' define which worksheet shall be imported
' open the source workbook, read only
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "VIP2", Selection, True
' close the source workbook without saving any changes
wb.Close False
Set wb = Nothing ' free memory
rec.Close
End Sub
the problem with the code is that it imports from the .xls as wished, but it creates me around 300 empty entries before showing me the first entry which is entered in row 2 on the xl spreadsheet.
Solution to this would be a way to check for empty fields and if yes, delete the whole line. (Eg. if field "Profile ID" is empty, delete whole line)
Further, I later want to import the data directly into an existing table, but i would need Access to understand that if the entry in the field "Profile ID" exists already, that it shall replace the existing one. However, no double existing entries may exist in the database (measured by the Profile ID).
Maybe someone can give me a hand on this since I dont know how to do this, respectively where to start.
Thanks for the help!
A2k