oxicottin
Learning by pecking away....
- Local time
- Yesterday, 20:37
- Joined
- Jun 26, 2007
- Messages
- 887
Hello, I need to import from Excel some data BUT not all data so after I import, I need to delete what is not needed. Using the below code behind my button to import it imports all the data from the workbook. In the image I need to only collect the data above the red line I drew in the image and delete everything below it.
I have a second question, the number I highlighted in green in my image, how can I collect that number in another temp table? This report is always the same it might just be longer or shorter in rows.
I have a second question, the number I highlighted in green in my image, how can I collect that number in another temp table? This report is always the same it might just be longer or shorter in rows.
Code:
Private Sub cmdImport4WeekSchedule_Click()
Const msoFileDialogFilePicker As Long = 3
Dim fDialog As Object
Dim myCurrentDir As String
'Dialog box to open to users Desktop
myCurrentDir = "C:\Documents and Settings\" & Environ("username") & "\Desktop\"
'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 'Instantiates the variable creating a filepicker object using late binding
With fDialog
.AllowMultiSelect = False 'Does not allow selecting more than one file
.InitialFileName = myCurrentDir 'Open the users desktop folder
.Title = "Please Select the 4 Week Schedule.xls File." 'Set the file dialog title
.Filters.Clear 'Clears the file dialog file type existing filters
.Filters.Add "Excel", "*.xls, *.xlsx" 'This file dialog will only allow the selection of .xls files
.Show
If .SelectedItems.Count = 1 Then 'A file was selected
'Delete the existing temperary table
Status "Deleting previous import table" 'Displays status in text box
On Error Resume Next 'Incase you deleted the tbl_Import4WeekSchedule table you wont get error
DoCmd.DeleteObject acTable, "tbl_Import4WeekSchedule"
On Error GoTo 0 'Turn back on error handeling
'IMPORTING SHEET from selected .xls file
Status "Importing 4 Week Schedule Data" 'Displays status in text box
DoCmd.TransferSpreadsheet acImport, , "tbl_Import4WeekSchedule", .SelectedItems(1), False
Else 'No file was selected give message
MsgBox ("No file was selected."), vbInformation, "No File"
End If
End With
End Sub