Command button to Import files (1 Viewer)

crc_love

New member
Local time
Today, 10:57
Joined
Nov 22, 2015
Messages
6
Greetings,

I need help with adding a command button to a form that will import data from an Excel file into a table. I am not a programmer at all and really need help. I have created an Overtime Hours table and need to add a command button to the form that will import the Overtime Hours Excel file into the table. So each week when I receive the Overtime spreadsheet from HR, I would like to click an Import button on my form that will pull the data from the spreadsheet into the existing Overtime Hours table.
 

crc_love

New member
Local time
Today, 10:57
Joined
Nov 22, 2015
Messages
6
Hi sneuberg,

I tried but received a run-time error. Here is exactly what I entered.

Private Sub Command0_Click()
DoCmd.TransferSpreadsheet acImport, 3, _
"Overtime Hours", "C:\Users\CRC\Documents\OVERTIME HOURS", True, "A1:G12"
End Sub
 

sneuberg

AWF VIP
Local time
Today, 07:57
Joined
Oct 17, 2014
Messages
3,506
What error did you get? The only thing I wonder about in your statement is the file name. Why doesn't it have an excel extension like "C:\Users\CRC\Documents\OVERTIME HOURS.XLS"
 

crc_love

New member
Local time
Today, 10:57
Joined
Nov 22, 2015
Messages
6
I figured out that the initial error was due to acImport,3 (used for Lotus). So I updated to acImport, 12.

New Values...
Private Sub Command0_Click()
DoCmd.TransferSpreadsheet acImport, 12, _
"States", "C:\Users\LACHONDA\Documents\STATES.xlsx", True, "A1:G12"
End Sub

Now I am receiving the below error.

A run-time error '2508':
A value you entered for the spreadsheettype argument is invalid.
 

sneuberg

AWF VIP
Local time
Today, 07:57
Joined
Oct 17, 2014
Messages
3,506
Try

DoCmd.TransferSpreadsheet acImport,acSpreadsheetTypeExcel12 , _
"States", "C:\Users\LACHONDA\Documents\STATES.xlsx", True, "A1:G12"
 

Users who are viewing this thread

Top Bottom