472,983 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Importing Excel

I am trying to import an excel file into Access 97. It looks perfectly all
right but, every time I try to import it, I get to the lst step and am told
that it was not imported due to an error. There is no further explanation.
What are the kinds of things that make this happen?

Thanks from an obvious rookie.

Gordon
Nov 13 '05 #1
9 3833
You might have better luck if you defined the table you want the data
to go into instead of letting the wizard try to figure things out.
Then when you run the wizard, there's a lot less guessing going on.

How are you trying to import? File, Get External Data...?

Nov 13 '05 #2
I've been doing a lot of importing from Excel lately, and have noticed that
it is the rare spreadsheet that imports cleanly. I've gone to using automation
to loop through rows and insert into a table myself. Are you interested in
this solution? If so, I'll post the code, but it's not a trivial solution and will
require tweaking for each spreadsheet you plan to import.

If you post back, I'll try to clean up the code and post it here.

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/
"jillandgordon" <ji***********@sbcglobal.net> wrote ...
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I
get to the lst step and am told that it was not imported due to an error. There is no further explanation. What are
the kinds of things that make this happen?

Thanks from an obvious rookie.

Gordon

Nov 13 '05 #3
Aww heck, I decided to write it up anyhow. You can download the code here ...

http://amazecreations.com/datafast/D...tfromexcel.zip

and the bulk of the logic is posted below. You'll need a table to map the columns
from Excel to Access. The code below is looking for one called ImportColumnSpecs.
The download doesn't have a form to launch it, so you'll have to run from the debug
window with a command like this ...

ProcessFileImport "C:\download\sales.xls","sales_import"

Good Luck

Option Compare Database
Option Explicit

Public Function ProcessFileImport(ByVal sFile As String, ByVal sTable As String) As String
On Error GoTo ProcessFileImport_Error

' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet

' Access object variables
Dim dbs As DAO.Database
Dim rstRead As DAO.Recordset
Dim rstWrite As DAO.Recordset
Dim fld As DAO.Field

' Declared variables
Dim bytWks As Byte
Dim bytMaxPages As Byte
Dim intStartRow As Integer
Dim strData As String
Dim intMaxRow As Integer
Dim strSQL As String
Dim strMsg As String
Dim intLastCol As Integer
Dim intRow As Integer
Dim strCurrFld As String
Dim intCol As Integer
Dim intLen As Integer
Dim varValue As Variant
Dim lngErrs As Long

Const cPassword As String = "xxx999"

DoCmd.Hourglass True

' Create the Excel Applicaiton, Workbook and Worksheet and Database object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sFile)
Set dbs = CurrentDb

' You could loop through sheets, but for this example, we'll just do one.
bytMaxPages = 1

' Sometimes there is header info, so the "Start Row" isn't the first one.
' Set this variable to the first row that contains actual data.
intStartRow = 2

For bytWks = 1 To bytMaxPages
' Initialize variables on each pass
Set wks = Nothing
Set rstRead = Nothing
intRow = intStartRow

' Load current worksheet. Find used range to determine row count.
Set wks = appExcel.Worksheets(bytWks)

' Optionally, you can protect / unprotect with a password
'wks.Unprotect (cPassword)

' You need to figure out how many rows this sheet contains, so to know
' how far down to read. That value is saved in intMaxRow
strData = wks.UsedRange.Address
intMaxRow = CInt(Mid(strData, InStrRev(strData, "$")))
strData = ""

' Go get the list of fields for this worksheet from the Field Map table
strSQL = "SELECT [AccessField], [OrdinalPosition] FROM ImportColumnSpecs " & _
"WHERE [ImportName]='" & sTable & "' ORDER BY [OrdinalPosition] ASC;"
Set rstRead = dbs.OpenRecordset(strSQL, dbOpenDynaset)

' If there is a mistake and no specification exists, then exit with message
If rstRead.BOF And rstRead.EOF Then
strMsg = "The import spec was not found. Cannot continue."
MsgBox strMsg, vbExclamation, "Error"
Else
rstRead.MoveLast
rstRead.MoveFirst
intLastCol = rstRead.RecordCount

' The name of the import and destination table should be the same for this
' code to function correctly.
Set rstWrite = dbs.OpenRecordset(sTable, dbOpenDynaset)
Do Until intRow > intMaxRow
' Check row to be sure it is not blank. If so, skip the row
For intCol = 1 To intLastCol
strData = strData & Trim(Nz(wks.Cells(intRow, intCol), ""))
Next

If strData = "" Then
intRow = intRow + 1
Else
rstWrite.AddNew
Do Until rstRead.EOF
' Loop through the list of fields, processing them one at a time.
' Grab the field name to simplify code and improve performance.
strCurrFld = Nz(rstRead!AccessField, "")
intCol = rstRead!OrdinalPosition

' Make sure that text fields truncate data at prescribed limits.
' Users may not enter supply more text than the fields can contain.
If dbs.TableDefs(sTable).Fields(strCurrFld).Type = dbText Then
intLen = dbs.TableDefs(sTable).Fields(strCurrFld).Size
varValue = Left(Nz(wks.Cells(intRow, intCol), ""), intLen)
Else
varValue = wks.Cells(intRow, intCol)
End If

' The database schema requires that empty fields contain NULL, not
' the empty string.
If varValue = "" Then varValue = Null

' Handle date columns. Sometimes Excel doesn't format them as dates
If InStr(1, strCurrFld, "Date") > 0 Then
If Not IsDate(varValue) Then
If IsNumeric(varValue) Then
On Error Resume Next
varValue = CDate(varValue)
If Err.Number <> 0 Then
If Left(CStr(varValue), 2) = "20" Then
varValue = CDate(Left(varValue, 4) & "-" & _
Mid(varValue, 5, 2) & "-" & _
Right(varValue, 2))
End If
Err.Clear
End If
On Error GoTo ProcessFileImport_Error
Else
lngErrs = lngErrs + 1
varValue = Null
End If
End If
rstWrite.Fields(strCurrFld) = varValue
Else
' If not a date field, then just write the value to the rst
rstWrite.Fields(strCurrFld) = varValue
End If

rstRead.MoveNext
Loop
If Not rstRead.BOF Then rstRead.MoveFirst

rstWrite.Update

' Reset the variables for processing of the next record.
strData = ""
intRow = intRow + 1
'Debug.Print intRow
End If
Loop
Set wks = Nothing
End If
Next

Exit_Here:
' Report results
strMsg = "finished"
ProcessFileImport = strMsg
' Cleanup all objects (resume next on errors)

On Error Resume Next
Set wks = Nothing
wbk.Close True
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rstRead = Nothing
Set rstWrite = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function

ProcessFileImport_Error:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here

End Function


--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Danny J. Lesandrini" <dl*********@hotmail.com> wrote in ...
I've been doing a lot of importing from Excel lately, and have noticed that
it is the rare spreadsheet that imports cleanly. I've gone to using automation
to loop through rows and insert into a table myself. Are you interested in
this solution? If so, I'll post the code, but it's not a trivial solution and will
require tweaking for each spreadsheet you plan to import.

If you post back, I'll try to clean up the code and post it here.

--

Nov 13 '05 #4
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before. I searched the ng and came across the post below. The code seemed to be just what the doctor ordered.

Ultimately I want to ensure the spreadsheet headings match the import table, and that a dummy row of data can be inserted into the sheet to ensure that alphanumeric fields load into text; right now the first 9 rows have numeric data and the import kicks all alphanumeric data from the field (in spite of the import table being predefined and having a text format).

However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook & Excel.Worksheet , for example. Obviously not intended for Access 97.

Is there an alternate mechanism to do this in A97? If not, what version is this meant for?

I'm hoping there's an easy way to do this. Any help would be appreciated.
--
Brian
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 9:16 am >>>
Aww heck, I decided to write it up anyhow. You can download the code here ...

http://amazecreations.com/datafast/D...tfromexcel.zip

and the bulk of the logic is posted below. You'll need a table to map the columns
from Excel to Access. The code below is looking for one called ImportColumnSpecs.
The download doesn't have a form to launch it, so you'll have to run from the debug
window with a command like this ...

ProcessFileImport "C:\download\sales.xls","sales_import"

Good Luck

Option Compare Database
Option Explicit

Public Function ProcessFileImport(ByVal sFile As String, ByVal sTable As String) As String
On Error GoTo ProcessFileImport_Error

' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet

' Access object variables
Dim dbs As DAO.Database
Dim rstRead As DAO.Recordset
Dim rstWrite As DAO.Recordset
Dim fld As DAO.Field

' Declared variables
Dim bytWks As Byte
Dim bytMaxPages As Byte
Dim intStartRow As Integer
Dim strData As String
Dim intMaxRow As Integer
Dim strSQL As String
Dim strMsg As String
Dim intLastCol As Integer
Dim intRow As Integer
Dim strCurrFld As String
Dim intCol As Integer
Dim intLen As Integer
Dim varValue As Variant
Dim lngErrs As Long

Const cPassword As String = "xxx999"

DoCmd.Hourglass True

' Create the Excel Applicaiton, Workbook and Worksheet and Database object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sFile)
Set dbs = CurrentDb

' You could loop through sheets, but for this example, we'll just do one.
bytMaxPages = 1

' Sometimes there is header info, so the "Start Row" isn't the first one.
' Set this variable to the first row that contains actual data.
intStartRow = 2

For bytWks = 1 To bytMaxPages
' Initialize variables on each pass
Set wks = Nothing
Set rstRead = Nothing
intRow = intStartRow

' Load current worksheet. Find used range to determine row count.
Set wks = appExcel.Worksheets(bytWks)

' Optionally, you can protect / unprotect with a password
'wks.Unprotect (cPassword)

' You need to figure out how many rows this sheet contains, so to know
' how far down to read. That value is saved in intMaxRow
strData = wks.UsedRange.Address
intMaxRow = CInt(Mid(strData, InStrRev(strData, "$")))
strData = ""

' Go get the list of fields for this worksheet from the Field Map table
strSQL = "SELECT [AccessField], [OrdinalPosition] FROM ImportColumnSpecs " & _
"WHERE [ImportName]='" & sTable & "' ORDER BY [OrdinalPosition] ASC;"
Set rstRead = dbs.OpenRecordset(strSQL, dbOpenDynaset)

' If there is a mistake and no specification exists, then exit with message
If rstRead.BOF And rstRead.EOF Then
strMsg = "The import spec was not found. Cannot continue."
MsgBox strMsg, vbExclamation, "Error"
Else
rstRead.MoveLast
rstRead.MoveFirst
intLastCol = rstRead.RecordCount

' The name of the import and destination table should be the same for this
' code to function correctly.
Set rstWrite = dbs.OpenRecordset(sTable, dbOpenDynaset)
Do Until intRow > intMaxRow
' Check row to be sure it is not blank. If so, skip the row
For intCol = 1 To intLastCol
strData = strData & Trim(Nz(wks.Cells(intRow, intCol), ""))
Next

If strData = "" Then
intRow = intRow + 1
Else
rstWrite.AddNew
Do Until rstRead.EOF
' Loop through the list of fields, processing them one at a time.
' Grab the field name to simplify code and improve performance.
strCurrFld = Nz(rstRead!AccessField, "")
intCol = rstRead!OrdinalPosition

' Make sure that text fields truncate data at prescribed limits.
' Users may not enter supply more text than the fields can contain.
If dbs.TableDefs(sTable).Fields(strCurrFld).Type = dbText Then
intLen = dbs.TableDefs(sTable).Fields(strCurrFld).Size
varValue = Left(Nz(wks.Cells(intRow, intCol), ""), intLen)
Else
varValue = wks.Cells(intRow, intCol)
End If

' The database schema requires that empty fields contain NULL, not
' the empty string.
If varValue = "" Then varValue = Null

' Handle date columns. Sometimes Excel doesn't format them as dates
If InStr(1, strCurrFld, "Date") > 0 Then
If Not IsDate(varValue) Then
If IsNumeric(varValue) Then
On Error Resume Next
varValue = CDate(varValue)
If Err.Number <> 0 Then
If Left(CStr(varValue), 2) = "20" Then
varValue = CDate(Left(varValue, 4) & "-" & _
Mid(varValue, 5, 2) & "-" & _
Right(varValue, 2))
End If
Err.Clear
End If
On Error GoTo ProcessFileImport_Error
Else
lngErrs = lngErrs + 1
varValue = Null
End If
End If
rstWrite.Fields(strCurrFld) = varValue
Else
' If not a date field, then just write the value to the rst
rstWrite.Fields(strCurrFld) = varValue
End If

rstRead.MoveNext
Loop
If Not rstRead.BOF Then rstRead.MoveFirst

rstWrite.Update

' Reset the variables for processing of the next record.
strData = ""
intRow = intRow + 1
'Debug.Print intRow
End If
Loop
Set wks = Nothing
End If
Next

Exit_Here:
' Report results
strMsg = "finished"
ProcessFileImport = strMsg
' Cleanup all objects (resume next on errors)

On Error Resume Next
Set wks = Nothing
wbk.Close True
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rstRead = Nothing
Set rstWrite = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function

ProcessFileImport_Error:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here

End Function


--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Danny J. Lesandrini" <dl*********@hotmail.com> wrote in ... I've been doing a lot of importing from Excel lately, and have noticed that
it is the rare spreadsheet that imports cleanly. I've gone to using automation
to loop through rows and insert into a table myself. Are you interested in
this solution? If so, I'll post the code, but it's not a trivial solution and will
require tweaking for each spreadsheet you plan to import.

If you post back, I'll try to clean up the code and post it here.

--



Nov 13 '05 #5
You need to set a reference to Excel. It doesn't matter which version you have, but the reference has to be set. Do
that and try compiling the code again.

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message news:pZ*******************@news20.bellglobal.com.. .
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before. I searched
the ng and came across the post below. The code seemed to be just what the doctor ordered.

Ultimately I want to ensure the spreadsheet headings match the import table, and that a dummy row of data can be
inserted into the sheet to ensure that alphanumeric fields load into text; right now the first 9 rows have numeric
data and the import kicks all alphanumeric data from the field (in spite of the import table being predefined and
having a text format).

However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook &
Excel.Worksheet , for example. Obviously not intended for Access 97.

Is there an alternate mechanism to do this in A97? If not, what version is this meant for?

I'm hoping there's an easy way to do this. Any help would be appreciated.
--
Brian
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 9:16 am >>>

Aww heck, I decided to write it up anyhow. You can download the code here ...

http://amazecreations.com/datafast/D...tfromexcel.zip

and the bulk of the logic is posted below. You'll need a table to map the columns
from Excel to Access. The code below is looking for one called ImportColumnSpecs.
The download doesn't have a form to launch it, so you'll have to run from the debug
window with a command like this ...

ProcessFileImport "C:\download\sales.xls","sales_import"

Good Luck

Option Compare Database
Option Explicit

Public Function ProcessFileImport(ByVal sFile As String, ByVal sTable As String) As String
On Error GoTo ProcessFileImport_Error

' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet

' Access object variables
Dim dbs As DAO.Database
Dim rstRead As DAO.Recordset
Dim rstWrite As DAO.Recordset
Dim fld As DAO.Field

' Declared variables
Dim bytWks As Byte
Dim bytMaxPages As Byte
Dim intStartRow As Integer
Dim strData As String
Dim intMaxRow As Integer
Dim strSQL As String
Dim strMsg As String
Dim intLastCol As Integer
Dim intRow As Integer
Dim strCurrFld As String
Dim intCol As Integer
Dim intLen As Integer
Dim varValue As Variant
Dim lngErrs As Long

Const cPassword As String = "xxx999"

DoCmd.Hourglass True

' Create the Excel Applicaiton, Workbook and Worksheet and Database object
Set appExcel = Excel.Application
Set wbk = appExcel.Workbooks.Open(sFile)
Set dbs = CurrentDb

' You could loop through sheets, but for this example, we'll just do one.
bytMaxPages = 1

' Sometimes there is header info, so the "Start Row" isn't the first one.
' Set this variable to the first row that contains actual data.
intStartRow = 2

For bytWks = 1 To bytMaxPages
' Initialize variables on each pass
Set wks = Nothing
Set rstRead = Nothing
intRow = intStartRow

' Load current worksheet. Find used range to determine row count.
Set wks = appExcel.Worksheets(bytWks)

' Optionally, you can protect / unprotect with a password
'wks.Unprotect (cPassword)

' You need to figure out how many rows this sheet contains, so to know
' how far down to read. That value is saved in intMaxRow
strData = wks.UsedRange.Address
intMaxRow = CInt(Mid(strData, InStrRev(strData, "$")))
strData = ""

' Go get the list of fields for this worksheet from the Field Map table
strSQL = "SELECT [AccessField], [OrdinalPosition] FROM ImportColumnSpecs " & _
"WHERE [ImportName]='" & sTable & "' ORDER BY [OrdinalPosition] ASC;"
Set rstRead = dbs.OpenRecordset(strSQL, dbOpenDynaset)

' If there is a mistake and no specification exists, then exit with message
If rstRead.BOF And rstRead.EOF Then
strMsg = "The import spec was not found. Cannot continue."
MsgBox strMsg, vbExclamation, "Error"
Else
rstRead.MoveLast
rstRead.MoveFirst
intLastCol = rstRead.RecordCount

' The name of the import and destination table should be the same for this
' code to function correctly.
Set rstWrite = dbs.OpenRecordset(sTable, dbOpenDynaset)
Do Until intRow > intMaxRow
' Check row to be sure it is not blank. If so, skip the row
For intCol = 1 To intLastCol
strData = strData & Trim(Nz(wks.Cells(intRow, intCol), ""))
Next

If strData = "" Then
intRow = intRow + 1
Else
rstWrite.AddNew
Do Until rstRead.EOF
' Loop through the list of fields, processing them one at a time.
' Grab the field name to simplify code and improve performance.
strCurrFld = Nz(rstRead!AccessField, "")
intCol = rstRead!OrdinalPosition

' Make sure that text fields truncate data at prescribed limits.
' Users may not enter supply more text than the fields can contain.
If dbs.TableDefs(sTable).Fields(strCurrFld).Type = dbText Then
intLen = dbs.TableDefs(sTable).Fields(strCurrFld).Size
varValue = Left(Nz(wks.Cells(intRow, intCol), ""), intLen)
Else
varValue = wks.Cells(intRow, intCol)
End If

' The database schema requires that empty fields contain NULL, not
' the empty string.
If varValue = "" Then varValue = Null

' Handle date columns. Sometimes Excel doesn't format them as dates
If InStr(1, strCurrFld, "Date") > 0 Then
If Not IsDate(varValue) Then
If IsNumeric(varValue) Then
On Error Resume Next
varValue = CDate(varValue)
If Err.Number <> 0 Then
If Left(CStr(varValue), 2) = "20" Then
varValue = CDate(Left(varValue, 4) & "-" & _
Mid(varValue, 5, 2) & "-" & _
Right(varValue, 2))
End If
Err.Clear
End If
On Error GoTo ProcessFileImport_Error
Else
lngErrs = lngErrs + 1
varValue = Null
End If
End If
rstWrite.Fields(strCurrFld) = varValue
Else
' If not a date field, then just write the value to the rst
rstWrite.Fields(strCurrFld) = varValue
End If

rstRead.MoveNext
Loop
If Not rstRead.BOF Then rstRead.MoveFirst

rstWrite.Update

' Reset the variables for processing of the next record.
strData = ""
intRow = intRow + 1
'Debug.Print intRow
End If
Loop
Set wks = Nothing
End If
Next

Exit_Here:
' Report results
strMsg = "finished"
ProcessFileImport = strMsg
' Cleanup all objects (resume next on errors)

On Error Resume Next
Set wks = Nothing
wbk.Close True
Set wbk = Nothing
appExcel.Quit
Set appExcel = Nothing
Set rstRead = Nothing
Set rstWrite = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
Exit Function

ProcessFileImport_Error:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here

End Function


--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Danny J. Lesandrini" <dl*********@hotmail.com> wrote in ...
I've been doing a lot of importing from Excel lately, and have noticed that
it is the rare spreadsheet that imports cleanly. I've gone to using automation
to loop through rows and insert into a table myself. Are you interested in
this solution? If so, I'll post the code, but it's not a trivial solution and will
require tweaking for each spreadsheet you plan to import.

If you post back, I'll try to clean up the code and post it here.

--


Nov 13 '05 #6
I wish I knew how... ??
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 1:07 pm >>>
You need to set a reference to Excel. It doesn't matter which version you have, but the reference has to be set. Do
that and try compiling the code again.

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before.
However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook &
Excel.Worksheet

Nov 13 '05 #7
Sorry about that. Didn't realize you haven't set references yet. You
will become very familiar with this in time.

Open any code module and select References from the Tools menu.
A dialog box will appear with some items checked (selected) at the
top of the list. Leave those alone and scroll down until you find one
named Microsoft Excel and select (check) the box. Save and close

Now, Choose Compile from the Debug menu and see if it throws any
errors.

To test my code, press Ctl+G to display the IMMEDIATE window and
type the following into the window ...

? ProcessFileImport ("C:\download\sales.xls","sales_import")

The Question Mark is shorthand for "Please print the result." It's
followed by the name of the procedure and it's arguments. The
first arg is the file path and name. The second is the name of the
table into which you are importing the data in the file.

My code is designed for my table and file. If you want to import
your own, you'll need to modify some things. It's not trivial, but
you can figure it out. Just follow the example for the sales table
and make the appropriate entries in table: ImportColumnSpecs.

Good luck
--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message news:x5*******************@news20.bellglobal.com.. .
I wish I knew how... ??
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 1:07 pm >>>

You need to set a reference to Excel. It doesn't matter which version you have, but the reference has to be set. Do
that and try compiling the code again.

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before.
However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook &
Excel.Worksheet

Nov 13 '05 #8
Thanks, Danny! Its always the obvious that's overlooked, isn't it? References are something I've managed to avoid, despite working on fairly significant apps for several years now. But there're always previously unused capabilities to learn about..

Selecting the reference as you indicated got me past the first error. Now I'm getting an undefined variable InStrRev in ProcessInputFile, but I've just DL'd the zip file. We'll see how we fare from here.

Thanks again!
--
Brian
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 2:35 pm >>>
Sorry about that. Didn't realize you haven't set references yet. You
will become very familiar with this in time.

Open any code module and select References from the Tools menu.
A dialog box will appear with some items checked (selected) at the
top of the list. Leave those alone and scroll down until you find one
named Microsoft Excel and select (check) the box. Save and close

Now, Choose Compile from the Debug menu and see if it throws any
errors.

To test my code, press Ctl+G to display the IMMEDIATE window and
type the following into the window ...

? ProcessFileImport ("C:\download\sales.xls","sales_import")

The Question Mark is shorthand for "Please print the result." It's
followed by the name of the procedure and it's arguments. The
first arg is the file path and name. The second is the name of the
table into which you are importing the data in the file.

My code is designed for my table and file. If you want to import
your own, you'll need to modify some things. It's not trivial, but
you can figure it out. Just follow the example for the sales table
and make the appropriate entries in table: ImportColumnSpecs.

Good luck
--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message news:x5*******************@news20.bellglobal.com.. .
I wish I knew how... ??
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 1:07 pm >>>

You need to set a reference to Excel. It doesn't matter which version you have, but the reference has to be set. Do
that and try compiling the code again.

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before.
However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook &
Excel.Worksheet



Nov 13 '05 #9
If you're using Access 97, you won't have that function. Try replacing it with this ...

Function LastInStr(strSearched As String, strSought As String) As Integer
On Error Resume Next

'//////////////////////////////////////////////////////////////////////////
'
' This function finds the last instance of a character within
' a string of characters and returns an integer representing
' the final position of the desired character.
'
' Typically, this function us used to find the final "\" in
' a file path string
'
'//////////////////////////////////////////////////////////////////////////

Dim intCurrVal As Integer
Dim intLastPosition As Integer

intCurrVal = InStr(strSearched, strSought)
Do Until intCurrVal = 0
intLastPosition = intCurrVal
intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
Loop
LastInStr = intLastPosition

End Function

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message news:iq*******************@news20.bellglobal.com.. .
Thanks, Danny! Its always the obvious that's overlooked, isn't it? References are something I've managed to avoid,
despite working on fairly significant apps for several years now. But there're always previously unused capabilities
to learn about..

Selecting the reference as you indicated got me past the first error. Now I'm getting an undefined variable InStrRev
in ProcessInputFile, but I've just DL'd the zip file. We'll see how we fare from here.

Thanks again!
--
Brian
Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 2:35 pm >>>

Sorry about that. Didn't realize you haven't set references yet. You
will become very familiar with this in time.

Open any code module and select References from the Tools menu.
A dialog box will appear with some items checked (selected) at the
top of the list. Leave those alone and scroll down until you find one
named Microsoft Excel and select (check) the box. Save and close

Now, Choose Compile from the Debug menu and see if it throws any
errors.

To test my code, press Ctl+G to display the IMMEDIATE window and
type the following into the window ...

? ProcessFileImport ("C:\download\sales.xls","sales_import")

The Question Mark is shorthand for "Please print the result." It's
followed by the name of the procedure and it's arguments. The
first arg is the file path and name. The second is the name of the
table into which you are importing the data in the file.

My code is designed for my table and file. If you want to import
your own, you'll need to modify some things. It's not trivial, but
you can figure it out. Just follow the example for the sales table
and make the appropriate entries in table: ImportColumnSpecs.

Good luck
--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast/

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message news:x5*******************@news20.bellglobal.com.. .
I wish I knew how... ??
> Danny J. Lesandrini<dl*********@hotmail.com> September 1, 2005 1:07 pm >>>

You need to set a reference to Excel. It doesn't matter which version you have, but the reference has to be set. Do
that and try compiling the code again.

"Brian Graham" <Gr*****@psac-afpc.com> wrote in message
I'm trying to automate the import of an Excel spreadsheet into Access. Something I've never done before.
However, when I invoke the code, the function bombs on bad keywords. Excel.Application Excel.Workbook &
Excel.Worksheet


Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Little PussyCat | last post by:
Hello, I nee to write something that will transfer excel data into an SQL Server table. I have for another database application I wrote have it importing Excel spreadsheet data using cell by...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
2
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
2
by: jereviscious | last post by:
Hi all - Last resort time. I'm importing data from a spreadsheet that I receive from one of my vendor using interop.excel. The date field in excel is entered as 4/7/2006, but when I retrieve...
5
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
28
by: kkadakia | last post by:
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.