Transferspreadsheet confusion

D

Dave

I understand that there is a transferspreadsheet command that I can
use to import certain cells of an excel file into a certain table of
my database. I will have the code assigned to a button.

There will be, however, several spreadsheets (same spreadsheet
structure, different patient) to pick from. How can I get user input
to select which spreadsheet file to import with the
transferspreadsheet command?

Thanks,

Dave B
 
K

Ken Snell \(MVP\)

Pieter's suggestion will let your user select the EXCEL file.

But you then will need to write VBA code that actually opens the EXCEL file,
gets a list of the spreadsheet names that are in that file, closes the file,
presents the list of spreadsheet names to the user (I find that a listbox is
the best control to use), and then the user would select the desired sheet
name so that your VBA code could pass the name to the TransferSpreadsheet
action.
--

Ken Snell
<MS ACCESS MVP>



"Pieter Wijnen"
 
F

fredg

I understand that there is a transferspreadsheet command that I can
use to import certain cells of an excel file into a certain table of
my database. I will have the code assigned to a button.

There will be, however, several spreadsheets (same spreadsheet
structure, different patient) to pick from. How can I get user input
to select which spreadsheet file to import with the
transferspreadsheet command?

Thanks,

Dave B

Here is a simple method:

Dim strSheet as String

strSheet = MsgBox("Enter the full path to the spreadsheet, and the
Spreadsheet name")
If(Right(strSheet,4) = ".xls" Then
Else
strSheet = strSheet & ".xls"
End If

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"YourTableName",strSheet

You can add the "Has Field Names" and the "Range" arguments to the
above code.

The complete path would look something like:
"c:\FolderName\MySpreadsheetName.xls"
 
P

Pieter Wijnen

inputbox might work better <g>

Pieter

fredg said:
Here is a simple method:

Dim strSheet as String

strSheet = MsgBox("Enter the full path to the spreadsheet, and the
Spreadsheet name")
If(Right(strSheet,4) = ".xls" Then
Else
strSheet = strSheet & ".xls"
End If

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9,
"YourTableName",strSheet

You can add the "Has Field Names" and the "Range" arguments to the
above code.

The complete path would look something like:
"c:\FolderName\MySpreadsheetName.xls"
 

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