473,405 Members | 2,444 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,405 software developers and data experts.

Importing data from Excel to Access 2007 but some data carries to the next lower cell

I am trying to import data from a linked Excel file, but when it was exported from the Supplier in CSV/XLSX format any data in the Description column that was longer than 35 characters it would be inserted to the next cell below showing up as a separate record in the Access Table.

How do I Join them together the description back together?
Attached Files
File Type: xlsx SampleData.xlsx (8.7 KB, 224 views)
Feb 12 '16 #1
7 1025
zmbd
5,501 Expert Mod 4TB
+ Is the field length setting for the [Description] field in the access table large enough to hold the extra data?

+ As this is a CSV file, it could be possible to open the file for I/O and parse thru it first using VBA removing the return at the end of the prior line.... Without the data, it's hard to provide more than pseudo code/logic

+ Would you be so kind as to enter the example data (just four rows should do :) ) as a table within a post? Use the [CODE/] format to hold the formatting and the <Space>s instead of <Tab>s for column formatting.
++ Many of our experts (I am one such) are not able to d/l unrequested attachments due to various IT-Security policies and/or firewall restrictions.

+ Information on the table design would also be most helpful.
[TableName]
[TableName]![FieldName] datatype (ie Autonumber, Text(25), etc) PK=Primary Key, FK = Foreign Key

-z
Feb 12 '16 #2
The Raw Data is in Excel. It is already separated. I don't have code to rejoin the Description.

I was thinking something like NextRecord(if(isNull([Column1]),([Column2] & NextRecord [Column2]).

Received data to import:
Column1---Column2
1881074---ZURN QQPC44X 3/4 BARB PEX POLY CPLG
3055338---SPECPROD P-1066 PIPE SUPPORT
----------BRACKET 2IN X 20IN W/EXTRA 1/2IN
----------HOLE 1/2INON 1IN CENTERS 3/4IN ON
----------4IN CENTERS

Data needs to be like after import:
Column1---Column2
1881074---ZURN QQPC44X 3/4 BARB PEX POLY CPLG
3055338---SPECPROD P-1066 PIPE SUPPORT BRACKET 2IN X 20IN W/EXTRA 1/2IN HOLE 1/2INON 1IN CENTERS 3/4IN ON 4IN CENTERS
Feb 12 '16 #3
Expand|Select|Wrap|Line Numbers
  1. 1637710    zurn q4ps20x 3/4x20 straight length
  2.     pex hot/cold wht tube
  3. 1881074    zurn qqpc44x 3/4 barb pex poly cplg
  4. 3055338    specprod p-1066 pipe support
  5.     bracket 2in x 20in w/extra 1/2in
  6.     hole 1/2inon 1in centers 3/4in on
  7.     4in centers
  8.  
Feb 12 '16 #4
jforbes
1,107 Expert 1GB
If I were doing this, I would stitch the Description back together when Importing the Spreadsheet instead of attempting to fix it later. It's usually easier that way.

I took something that I had that was sort of similar and tweaked it to work with your data. Here is the result:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  2.     On Error GoTo ErrorOut
  3.  
  4.     Dim sSpreadsheet As String
  5.     Dim oExcel As Excel.Application
  6.     Dim oWorkbook As Excel.Workbook
  7.     Dim oSheets As Excel.Sheets
  8.     Dim oSheet As Excel.Worksheet
  9.  
  10.     Dim lCount As Long
  11.     Dim sSQL As String
  12.     Dim sColumn1 As String
  13.     Dim sColumn2 As String
  14.     Dim sDescription As String
  15.  
  16.     ' Open the Spreadsheet
  17.     sSpreadsheet = "C:\Users\Desktop\Bytes\SampleData.xlsx"
  18.     Set oExcel = New Excel.Application
  19.     Set oWorkbook = oExcel.Workbooks.Open(sSpreadsheet, ReadOnly:=True)
  20.     Set oSheets = oWorkbook.Sheets
  21.     Set oSheet = oWorkbook.Sheets(1)
  22.     For lCount = 1 To oSheet.Rows.Count
  23.  
  24.         ' get Columns
  25.         sColumn1 = oSheet.Cells(lCount, 1).Value
  26.         sColumn2 = oSheet.Cells(lCount, 2).Value
  27.  
  28.         ' Test for New Row
  29.         If Len(sColumn1) > 0 Then
  30.  
  31.             ' Insert Previous Row, if there is one
  32.             If Len(sSQL) > 0 Then
  33.                 sSQL = sSQL & sDescription & "')"
  34.                 CurrentDb.Execute (sSQL)
  35.             End If
  36.  
  37.             ' Build up new Row SQL
  38.             sSQL = "INSERT INTO ExcelImport ( Column1, Column2) VALUES ( '" & sColumn1 & "', '"
  39.             sDescription = sColumn2
  40.         Else
  41.  
  42.             ' Row might Continue, Add additional Description
  43.             sDescription = sDescription & " " & sColumn2
  44.  
  45.             ' Test for completely blank Row and end of Spreadsheet
  46.             If Len(sColumn2) = 0 Then
  47.                 If Len(sSQL) > 0 Then
  48.                     ' Insert Last Row
  49.                     sSQL = sSQL & sDescription & "')"
  50.                     CurrentDb.Execute (sSQL)
  51.                 End If
  52.  
  53.                 'Exit out of Looping
  54.                 Exit For
  55.             End If
  56.         End If
  57.  
  58.     Next lCount
  59.  
  60.     MsgBox "Import complete.  " & lCount & " rows processed."
  61.  
  62. ExitOut:
  63.     'Clean up and release the Spreadsheet if it is opened
  64.     If Not oWorkbook Is Nothing Then
  65.         oWorkbook.Close SaveChanges:=False
  66.         Set oWorkbook = Nothing
  67.     End If
  68.     If Not oExcel Is Nothing Then
  69.         oExcel.Quit
  70.         Set oExcel = Nothing
  71.     End If
  72.     Exit Sub
  73.  
  74. ErrorOut:
  75.     MsgBox (Err.Description)
  76.     Resume ExitOut
  77. End Sub
You'll need to play around with it and make it yours, but I think that should get you going in the right direction. You'll also need to add a reference to the Excel object library in the Visual Basic IDE.
Feb 13 '16 #5
jforbes reading your code I believe that you have the solution to my problem. New problem is that I am not that proficient in SQL/VBA. Is there a MS Access solution?

Thanks for the code, I will try to stumble though VBA to see if I can get the code to work.
Feb 13 '16 #6
NeoPa
32,556 Expert Mod 16PB
Hat2Boots:
New problem is that I am not that proficient in SQL/VBA. Is there a MS Access solution?
They're all part of Access to be fair, but certainly SQL, and then VBA, are increasingly complex areas of the whole product. It's usual to start with the basics then move on to working with the SQL directly and then, later still, to get more into the VBA side of things.

Unfortunately for you, in this particular instance, what you need requires VBA and SQL. I see no way to accomplish it without.
Feb 14 '16 #7
jforbes
1,107 Expert 1GB
I agree with NeoPa, there is not a native point and click solution for your situation that I can think of. One way or another it will involve either SQL, VBA, both SQL and VBA, or manually correcting the data.

...Searching the Internet, there seem to be some third party solutions that might work in Excel to merge the rows before they are imported, but I've not tried any. If you would rather not take the plunge into developing in Access, this may be a solution for you, but this sort of thing usually comes with a dollar value attached to it.
Feb 14 '16 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
0
by: Michael Malafronte | last post by:
Whenever I try to either Link or Import a Sybase or Sql database table to Access, it freezes.
1
by: farseer | last post by:
Hi, i would like to write an app that will do the following: 1. download a csv file from an http url. fields are delimited by the "|" 2. i would like to import this into an access database...
7
by: freeskier | last post by:
Hello, I am looking for some advice on collecting data. We are working on collecting about 20 different data points from 60 initial people, later to be expanded to approximately 200. At present we...
4
by: Milan Mehta | last post by:
I am new to Access. I have developed an application in Access 2007. I have kept all the tables in a MDB file and all the forms in a seperate accdb file. All the tables of MDF file is link in the...
1
by: MBlock316 | last post by:
Hello everyone, I am trying to import a Microsoft Excel 2007 formatted file into my application. I found on another thread in another forum that I needed to install the 2007 Office System Driver:...
0
by: bkberg05 | last post by:
Hi - I currently use Access 2003 and have documents stored in an OLE data type field. I want be able to write a query that contains various other data elements from the table plus the OLE field and...
5
by: zuraberadze | last post by:
I can't connect C# to MS Access 2007 to insert data into DB. please help me. it can't see the type of db. thx
0
by: newsco | last post by:
Dear all, I use VB6 ADO connect to Access 2007 accdb database, everything is fine except I cannot retrieve image file stored in the Access 2007 attachment data type. Can anyone show me some vb...
0
by: Elaine Huseby | last post by:
I have a form "PartsAndInvoices that has all the parts in the database listed in split form view. I want the user to use Access 2007's filter section on the ribbon to choose mutiple filters....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.