I have a form that import data from excel from Access. I have written a code that Import data but i want to Import data on the basis of criteria as if the field datatype has text as "Cap" it should import that data to table "tblCap", if it have text as "Gen" it should import all those rows to "tblGen", is there any way to do that?
Attach is a code for import.
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
If .Show Then
selectFile = .SelectedItems(1)
'stop execution if nothing selected
Set fd = Nothing
Private Sub Command0_Click()
On Error GoTo ErrorHandler
'disable ms access warnings
'Delete existing data in table
'This is optional. If you are combining spreadsheets
'in your table, don't run this query
'DoCmd.RunSQL "DELETE * FROM names"
DoCmd.TransferSpreadsheet acImport, 8, "tblCapacity", selectFile(), True
MsgBox "Import Successful"
're-enable ms access warnings
MsgBox "There was an Error: " & Err & ": " & Error(Err)