Import data from Excel

M

Mike

In my Access 2000 database I sometimes import data from MS Excel files.
For that purpose I have a form with a control button with the following
OnClick event:

Dim strSQL As String
Const Q = "'"

strSQL = "INSERT INTO MyTable ( BranchID, Date, Amount) " & _
"SELECT BranchID, Date, Amount " & _
"FROM [ExcelSheet$] IN " & Q & Me.FilePath & Q & " [EXCEL 5.0;]"

CurrentDb.Execute strSQL, dbFailOnError
End If

It works fine.

Now I need to make something alike, but instead of "BranchID" value from
ExcelSheet a constant should be inserted, e.g. "01".
Simply speaking:
- field "BranchID" should be always filled with "01" value;
- field "Date" should take values from "Date" column in Excel File;
- field "Amount" should take values from "Amount" column in Excel File;

Is it possible?
Thanks in advance!
 
A

Andi Mayer

In my Access 2000 database I sometimes import data from MS Excel files.
For that purpose I have a form with a control button with the following
OnClick event:

Dim strSQL As String
Const Q = "'"

strSQL = "INSERT INTO MyTable ( BranchID, Date, Amount) " & _
"SELECT BranchID, Date, Amount " & _
"FROM [ExcelSheet$] IN " & Q & Me.FilePath & Q & " [EXCEL 5.0;]"

CurrentDb.Execute strSQL, dbFailOnError
End If

It works fine.

Now I need to make something alike, but instead of "BranchID" value from
ExcelSheet a constant should be inserted, e.g. "01".
Simply speaking:
- field "BranchID" should be always filled with "01" value;
- field "Date" should take values from "Date" column in Excel File;
- field "Amount" should take values from "Amount" column in Excel File;

Is it possible?

2nd line:
SELECT '01' as F1, Date, Amount "
 

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