473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Excel Import Problems

I'm hoping the answer to this is that I'm just doing something silly,
but I'm really scratching my head over this one. I'm importing data
from multiple workbooks, each workbook has a sheet called SubSAT and I
need to get specific data from that into the database.

I'm finding that if I have the workbook open on my desktop then the
SubSAT % complete and the High level plan % come in fine, but as soon
as the workbook is closed they come into the import table but the
target table will not accept the value. I've tried Cdbl and this
doesn't work, the difference appears to be then when it's open the
values come in as 0.69 but when it is closed they come in as 69% and
this upsets it.

I've put the offending code below, does anyone have any ideas as to
what is causing the difference in the data types, or what type
conversion will heal it?

All help much appreciated.

startcol = "A"
endcol = "M"
XLTARGET = "Temp_Data_SubSAT"
HLP_Start = 1 'high level plan start and end row are fixed and uniform
HLP_End = 16
AOD_Start = 17 'AOD list start row is fixed and uniform
AOD_End = 40 'AOD list end row is not fixed or uniform, this is as long
as I think it will get
Detail_Start = 26 'AOD detail start row, not fixed but this will be the
lowest
Detail_End = 300 'AOD detail end row, not fixed this is a guess at the
furthest it will go

DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Temp_Data_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_AOD_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_Build_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from Temp_Data_AOD_Detail_SubSAT" 'Clear table

Set xlApp = CreateObject("Excel.Application")
'Path of the file being imported
Workbook_Array = Array("D:\N15_Charts\FDP CTR iFACTS.xls")
'"D:\N15_Charts\FDP CTR iFACTS.xls", "D:\N15_Charts\ADS_&_TOOLS CTR
iFACTS.xls", "D:\N15_Charts\CMTOOLS CTR iFACTS.xls",
"D:\N15_Charts\MSRS_&_RAP CTR iFACTS.xls", "D:\N15_Charts\RDP & CMS CTR
iFACTS.xls", "D:\N15_Charts\SEC CTR iFACTS.xls", "D:\N15_Charts\WDM &
SCC CTR iFACTS.xls", "D:\N15_Charts\CGW_&_SIS CTR iFACTS.xls",
"D:\N15_Charts\CxSS CTR iFACTS.xls")
For Each intI In Workbook_Array
strPath = intI
'Establish workbook string
Set xlBook = xlApp.workbooks.Open(strPath, False, True)
'Loop through all the Sheets in the workbook
For Each xlSheet In xlBook.Worksheets
On Error Resume Next
sheetRange = xlSheet.Name
If sheetRange Like "SubSAT" & "*" Then

range = startcol & HLP_Start & ":" & endcol & HLP_End

'Transfer the data from the worksheet
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel5, _
XLTARGET, _
strPath, _
False, _
sheetRange & "!" & range

Set rst_import =
Current_DB.OpenRecordset("Temp_Data_SubSAT")
Set rst_target_build =
Current_DB.OpenRecordset("CSCI_Build_SubSAT")

rst_import.MoveFirst
CSCI = rst_import!F1.Value

rst_import.MoveNext
rst_import.MoveNext
rst_target_build.AddNew
rst_target_build![CSCI] = CSCI
rst_target_build![Build] = Build

rst_target_build!SubSAT_ETC = rst_import!F7.Value
rst_import.MoveNext
rst_target_build![Planned End Date] =
CDate(rst_import!F7.Value)
rst_import.MoveNext
MsgBox "SubSAT % complete" & rst_import!F8.Value
rst_target_build![SubSAT_%_Comp] = rst_import!F8.Value
rst_import.MoveNext
MsgBox "HLP % complete" & CDbl(rst_import!F9.Value)
rst_target_build![High_Level_Plan_%_Comp] =
CDbl(rst_import!F9.Value)
rst_target_build.Update
End If

Next
'MsgBox "Complete " & strPath
Next

xlBook.Application.Quit

'Error Handler used to catch error when the fields are blank
Exit Function

Exit_Handler:
On Error Resume Next

Err_Handler:
On Error Resume Next
End Function

Sep 6 '06 #1
2 3469
madeleine,

I think it is not the most easy and flexible way to import data from
Excel-worksheets but I think the main obstacle could be the numeric
datatype used in the target table. To be able to accept percentual
values this should be some form of floating point format or fractional
data accepting datatype and not some form of scaled integer type often
used when declared as numeric datatype. a cdbl-function doesn't change
the receiving field-datatype, but only will convert the source data
into double precision floating point format before deliverig it to your
target table. If this contains some form of integer datatype
(implicitly scaled integers as well) it wil throw away the fractional
data expected from a percentage-value below 100%. If a scaled type is
used with a scalefactor of 1000 (3 digits behind the decimal point) the
values first have to be muliplicated with 1000 to be accepted.

If I would import some values from Excel-sheets I would consider giving
the cells or ranges a unique and meaningful name within the spreadsheet
and importing them as tables from an Excel-sheet directly. In that case
however a setup of the Excel sheet that cannot easily be corrupted by
end-users containing other than the ecpectyed values and datatypes is
needed to prevent worthless input. It all can be done and even
automated upto some point without use of VBA. Only if full automation
and extensive detection of possible errors, full validation of the
spreadsheet and logging of all imports is needed use of VBA will not be
avoidable.

Marc

madeleine schreef:
I'm hoping the answer to this is that I'm just doing something silly,
but I'm really scratching my head over this one. I'm importing data
from multiple workbooks, each workbook has a sheet called SubSAT and I
need to get specific data from that into the database.

I'm finding that if I have the workbook open on my desktop then the
SubSAT % complete and the High level plan % come in fine, but as soon
as the workbook is closed they come into the import table but the
target table will not accept the value. I've tried Cdbl and this
doesn't work, the difference appears to be then when it's open the
values come in as 0.69 but when it is closed they come in as 69% and
this upsets it.

I've put the offending code below, does anyone have any ideas as to
what is causing the difference in the data types, or what type
conversion will heal it?

All help much appreciated.

startcol = "A"
endcol = "M"
XLTARGET = "Temp_Data_SubSAT"
HLP_Start = 1 'high level plan start and end row are fixed and uniform
HLP_End = 16
AOD_Start = 17 'AOD list start row is fixed and uniform
AOD_End = 40 'AOD list end row is not fixed or uniform, this is as long
as I think it will get
Detail_Start = 26 'AOD detail start row, not fixed but this will be the
lowest
Detail_End = 300 'AOD detail end row, not fixed this is a guess at the
furthest it will go

DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Temp_Data_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_AOD_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_Build_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from Temp_Data_AOD_Detail_SubSAT" 'Clear table

Set xlApp = CreateObject("Excel.Application")
'Path of the file being imported
Workbook_Array = Array("D:\N15_Charts\FDP CTR iFACTS.xls")
'"D:\N15_Charts\FDP CTR iFACTS.xls", "D:\N15_Charts\ADS_&_TOOLS CTR
iFACTS.xls", "D:\N15_Charts\CMTOOLS CTR iFACTS.xls",
"D:\N15_Charts\MSRS_&_RAP CTR iFACTS.xls", "D:\N15_Charts\RDP & CMS CTR
iFACTS.xls", "D:\N15_Charts\SEC CTR iFACTS.xls", "D:\N15_Charts\WDM &
SCC CTR iFACTS.xls", "D:\N15_Charts\CGW_&_SIS CTR iFACTS.xls",
"D:\N15_Charts\CxSS CTR iFACTS.xls")
For Each intI In Workbook_Array
strPath = intI
'Establish workbook string
Set xlBook = xlApp.workbooks.Open(strPath, False, True)
'Loop through all the Sheets in the workbook
For Each xlSheet In xlBook.Worksheets
On Error Resume Next
sheetRange = xlSheet.Name
If sheetRange Like "SubSAT" & "*" Then

range = startcol & HLP_Start & ":" & endcol & HLP_End

'Transfer the data from the worksheet
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel5, _
XLTARGET, _
strPath, _
False, _
sheetRange & "!" & range

Set rst_import =
Current_DB.OpenRecordset("Temp_Data_SubSAT")
Set rst_target_build =
Current_DB.OpenRecordset("CSCI_Build_SubSAT")

rst_import.MoveFirst
CSCI = rst_import!F1.Value

rst_import.MoveNext
rst_import.MoveNext
rst_target_build.AddNew
rst_target_build![CSCI] = CSCI
rst_target_build![Build] = Build

rst_target_build!SubSAT_ETC = rst_import!F7.Value
rst_import.MoveNext
rst_target_build![Planned End Date] =
CDate(rst_import!F7.Value)
rst_import.MoveNext
MsgBox "SubSAT % complete" & rst_import!F8.Value
rst_target_build![SubSAT_%_Comp] = rst_import!F8.Value
rst_import.MoveNext
MsgBox "HLP % complete" & CDbl(rst_import!F9.Value)
rst_target_build![High_Level_Plan_%_Comp] =
CDbl(rst_import!F9.Value)
rst_target_build.Update
End If

Next
'MsgBox "Complete " & strPath
Next

xlBook.Application.Quit

'Error Handler used to catch error when the fields are blank
Exit Function

Exit_Handler:
On Error Resume Next

Err_Handler:
On Error Resume Next
End Function
Sep 7 '06 #2
Marc

Thanks for providing me with a better insight to the joys of Excel and
importing. What I'm finding most bizarre is the fact that if the
spreadsheet is closed when I run the module, it would import quite
happily, it would take the % as a floating point number and happily
convert it. If the spreadsheet was open and visible when I ran the
module it would take the % as a % and not bring it in, which I now
understand thanks to your explanation.

The only thing I could do to get round it in the end was to make sure
that I kept the spreadsheet closed to run the module (even though the
module opens it anyway), I have to assume that somehow the data is seen
differently when it is open and visible, that the Excel formatting is
not stored with the data and the data is formatted when the spreadsheet
is made visible rather than just opened.

Your explanation of why it has a problem with the data is most handy
and I will definitely be referring to it in the future.

Thanks very much.

Madeleine
MarcHG wrote:
madeleine,

I think it is not the most easy and flexible way to import data from
Excel-worksheets but I think the main obstacle could be the numeric
datatype used in the target table. To be able to accept percentual
values this should be some form of floating point format or fractional
data accepting datatype and not some form of scaled integer type often
used when declared as numeric datatype. a cdbl-function doesn't change
the receiving field-datatype, but only will convert the source data
into double precision floating point format before deliverig it to your
target table. If this contains some form of integer datatype
(implicitly scaled integers as well) it wil throw away the fractional
data expected from a percentage-value below 100%. If a scaled type is
used with a scalefactor of 1000 (3 digits behind the decimal point) the
values first have to be muliplicated with 1000 to be accepted.

If I would import some values from Excel-sheets I would consider giving
the cells or ranges a unique and meaningful name within the spreadsheet
and importing them as tables from an Excel-sheet directly. In that case
however a setup of the Excel sheet that cannot easily be corrupted by
end-users containing other than the ecpectyed values and datatypes is
needed to prevent worthless input. It all can be done and even
automated upto some point without use of VBA. Only if full automation
and extensive detection of possible errors, full validation of the
spreadsheet and logging of all imports is needed use of VBA will not be
avoidable.

Marc

madeleine schreef:
I'm hoping the answer to this is that I'm just doing something silly,
but I'm really scratching my head over this one. I'm importing data
from multiple workbooks, each workbook has a sheet called SubSAT and I
need to get specific data from that into the database.

I'm finding that if I have the workbook open on my desktop then the
SubSAT % complete and the High level plan % come in fine, but as soon
as the workbook is closed they come into the import table but the
target table will not accept the value. I've tried Cdbl and this
doesn't work, the difference appears to be then when it's open the
values come in as 0.69 but when it is closed they come in as 69% and
this upsets it.

I've put the offending code below, does anyone have any ideas as to
what is causing the difference in the data types, or what type
conversion will heal it?

All help much appreciated.

startcol = "A"
endcol = "M"
XLTARGET = "Temp_Data_SubSAT"
HLP_Start = 1 'high level plan start and end row are fixed and uniform
HLP_End = 16
AOD_Start = 17 'AOD list start row is fixed and uniform
AOD_End = 40 'AOD list end row is not fixed or uniform, this is as long
as I think it will get
Detail_Start = 26 'AOD detail start row, not fixed but this will be the
lowest
Detail_End = 300 'AOD detail end row, not fixed this is a guess at the
furthest it will go

DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Temp_Data_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_AOD_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from CSCI_Build_SubSAT" 'Clear table
DoCmd.RunSQL "delete * from Temp_Data_AOD_Detail_SubSAT" 'Clear table

Set xlApp = CreateObject("Excel.Application")
'Path of the file being imported
Workbook_Array = Array("D:\N15_Charts\FDP CTR iFACTS.xls")
'"D:\N15_Charts\FDP CTR iFACTS.xls", "D:\N15_Charts\ADS_&_TOOLS CTR
iFACTS.xls", "D:\N15_Charts\CMTOOLS CTR iFACTS.xls",
"D:\N15_Charts\MSRS_&_RAP CTR iFACTS.xls", "D:\N15_Charts\RDP & CMS CTR
iFACTS.xls", "D:\N15_Charts\SEC CTR iFACTS.xls", "D:\N15_Charts\WDM &
SCC CTR iFACTS.xls", "D:\N15_Charts\CGW_&_SIS CTR iFACTS.xls",
"D:\N15_Charts\CxSS CTR iFACTS.xls")
For Each intI In Workbook_Array
strPath = intI
'Establish workbook string
Set xlBook = xlApp.workbooks.Open(strPath, False, True)
'Loop through all the Sheets in the workbook
For Each xlSheet In xlBook.Worksheets
On Error Resume Next
sheetRange = xlSheet.Name
If sheetRange Like "SubSAT" & "*" Then

range = startcol & HLP_Start & ":" & endcol & HLP_End

'Transfer the data from the worksheet
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel5, _
XLTARGET, _
strPath, _
False, _
sheetRange & "!" & range

Set rst_import =
Current_DB.OpenRecordset("Temp_Data_SubSAT")
Set rst_target_build =
Current_DB.OpenRecordset("CSCI_Build_SubSAT")

rst_import.MoveFirst
CSCI = rst_import!F1.Value

rst_import.MoveNext
rst_import.MoveNext
rst_target_build.AddNew
rst_target_build![CSCI] = CSCI
rst_target_build![Build] = Build

rst_target_build!SubSAT_ETC = rst_import!F7.Value
rst_import.MoveNext
rst_target_build![Planned End Date] =
CDate(rst_import!F7.Value)
rst_import.MoveNext
MsgBox "SubSAT % complete" & rst_import!F8.Value
rst_target_build![SubSAT_%_Comp] = rst_import!F8.Value
rst_import.MoveNext
MsgBox "HLP % complete" & CDbl(rst_import!F9.Value)
rst_target_build![High_Level_Plan_%_Comp] =
CDbl(rst_import!F9.Value)
rst_target_build.Update
End If

Next
'MsgBox "Complete " & strPath
Next

xlBook.Application.Quit

'Error Handler used to catch error when the fields are blank
Exit Function

Exit_Handler:
On Error Resume Next

Err_Handler:
On Error Resume Next
End Function
Sep 11 '06 #3

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

Similar topics

1
by: Richard Holliingsworth | last post by:
Hello: Thanks for your quick response. I'm trying to import a new Excel file into an A2K table and it's truncating the data. One of the Excel columns is a text field that can be up to 2000...
0
by: Jedawi | last post by:
Hi, would anyone be able to point me in the right direction on how to import an image (.jpg file) into an Excel worksheet using VB.Net and Option Strict On. This should be straight forward...
1
by: maztoo | last post by:
Hi I've seen this problem posted on this group in the past but I am yet to find a solution to the problem. I'm trying to import a simple spreadsheet into Access but am getting a message saying...
0
by: Grip | last post by:
Hi, I have gone throught the group and Microsoft's online help and have seen many suggestions but I am still seeking clarity: 1. I have an excel spreadsheet. Column A contains text that may...
0
by: liam_jones | last post by:
I'm very new to Python, well IronPython to precise, and have been having problems when using Excel. The problem I'm having is the closing of my Excel object. I'm able to successfully quit the...
0
by: Yvonne | last post by:
I've had on going problems trying to import data from an Excel spreadsheet in to Access 2002. I checked to make sure that the field names were EXACTLY the same, but no go. The only way round it was...
3
by: D.Stone | last post by:
I'm trying to import an Excel spreadsheet into an existing Access table using Office 2003. Ultimately, the plan is to do it programmatically using TransferSpreadsheet, but to check that the file...
3
by: scoots987 | last post by:
What do others do if you need to import excel files into SQL Server? My main problems are 1) zipcode formatting issues. If the column is a mix of zip and zip+4, I have problems retrieving all...
0
by: ishay44 | last post by:
Hello! I try to build (using Visual 2005 and Excel 2007) the example described in the Microsoft Help and Support "How to automate Excel from MFC and Visual C++ 2005 or Visual C++ .NET to fill or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.