importing from Excel To Access

C

corkster

I have established an import button with the following code. It works
fine for importing except, some of the header/column names in the
Excel spreadsheets have been changed which causes an error in
importing. Also, when importing I sometimes get blank rows in the
database using code below.

a few questions I have are:

1. Is there away for the import to programmatically change the column
headings before import?
2. Is there vba or other means for the import to disregard the column
headings and just import the data for that column?
3. Is there away to programmatically or other means to disregard
column headings as first row, considering database has that header
information.
4. what would need to be changed in the code to help do this?

Any tips, insights and additional information on this would be greatly
appreciated.

thanks

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click


Dim strFile As String
Dim strFolder As String


strFolder = "C:\1 corey projects\HEC\test import\"

strFile = "*.xls"
strFile = Dir(strFolder & strFile)


Do While Len(strFile) > 0
'MsgBox strFile 'temp error checking to verify loop is working
DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "Quarter1", _
strFolder + strFile, True, "A2:T"
strFile = Dir
'DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"Quarter1", strFolder + strFile, , "A:T"
' strFile = Dir
Loop

MsgBox "Importing Completed "

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub
 
C

corkster

I have established an import button with the following code. It works
fine for importing except, some of the header/column names in the
Excel spreadsheets have been changed which causes an error in
importing. Also, when importing I sometimes get blank rows in the
database using code below.

a few questions I have are:

1. Is there away for the import to programmatically change the column
headings before import?
2. Is there vba or other means for the import to disregard the column
headings and just import the data for that column?
3. Is there away to programmatically or other means to disregard
column headings as first row, considering database has that header
information.
4. what would need to be changed in the code to help do this?

Any tips, insights and additional information on this would be greatly
appreciated.

thanks

Private Sub Command0_Click()
On Error GoTo Err_Command0_Click

Dim strFile As String
Dim strFolder As String

strFolder = "C:\1 corey projects\HEC\test import\"

strFile = "*.xls"
strFile = Dir(strFolder & strFile)

Do While Len(strFile) > 0
'MsgBox strFile 'temp error checking to verify loop is working
DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "Quarter1", _
strFolder + strFile, True, "A2:T"
strFile = Dir
'DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"Quarter1", strFolder + strFile, , "A:T"
' strFile = Dir
Loop

MsgBox "Importing Completed "

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub

Forgot I am using access 2002
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top