473,612 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Follow up to previous post: Need code to import into access/Autonumber

I was trying to tihnk of solutions to the table in access being out of order
when i use:
DoCmd.TransferS preadsheet in code to import an excel file.
1. I could read the excel file from access. Does anyody have access code
to open an exel sheet and read it into a table in access in code?

2. have the user maintain an autonumber like field. THis way, I can have
this to sort on when I import it. Does excel have an autonumber field?

Thanks
Nov 13 '05 #1
2 2259
Some sample code for reading EXCEL spreadsheet and writing to recordset that
may get you started:

Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set xlx = CreateObject("E xcel.Applicatio n")
xlx.Visible = True
Set xlw = xlx.Workbooks.O pen("C:\Filenam e.xls"), , True
Set xls = xlw.Worksheets( "WorksheetName" )
Set xlc = xls.Range("A1")
Set dbs = CurrentDb()
Set rst = dbs.OpenRecords et("TableName" , dbOpenDynaset, dbAppendOnly)
Do While xlc.Value <> ""
rst.AddNew
For lngColumn = 0 To rst.Fields.Coun t - 1
rst.Fields(lngC olumn).Value = xlc.Offset(0, lngColumn).Valu e
Next lngColumn
rst.Update
Set xlc = xlc.Offset(1,0)
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
xlx.Quit
Set xlx = Nothing
--

Ken Snell
<MS ACCESS MVP>

"Danny" <da********@hot mail.com> wrote in message
news:iX******** **************@ news4.srv.hcvln y.cv.net...
I was trying to tihnk of solutions to the table in access being out of order when i use:
DoCmd.TransferS preadsheet in code to import an excel file.
1. I could read the excel file from access. Does anyody have access code
to open an exel sheet and read it into a table in access in code?

2. have the user maintain an autonumber like field. THis way, I can have
this to sort on when I import it. Does excel have an autonumber field?

Thanks

Nov 13 '05 #2
"Danny" <da********@hot mail.com> wrote ...
I was trying to tihnk of solutions to the table in access being out of order


I assume that by 'table in access' you mean a table in a Jet database.

The physical (e.g. on disk) ordering of a database table is determined
by its clustered index. The performance advantage of the clustered
index (physical order) is obvious e.g. think of how a paper copy
telephone directory is ordered by last name, first names.

The clustered index is a fundamental concept of table design which Jet
does not expose to the user e.g.

CREATE CLUSTERED INDEX my_index ON MyTable (MyKeyColumn)

will fail with a syntax error, remove the CLUSTERED and it is OK.
However, Jet tables do of course have a clustered index, being the
primary key (PK). This is why an IDENTITY/autonumber (or a homemade
incrementing integer) column is never a good choice for PK; imagine
now a telephone directory ordered by telephone number. If the IDENTITY
column is required to enforce uniqueness for the sake of it, define
your PK column as (meaningful_tex t_column, IDENTITY_column ).

Also bear in mind that a Jet clustered index is only rebuilt when the
database file is compacted. Any rows added to the table subsequent to
the last compact will be added unordered to the 'bottom' of the table.

Jamie.

--
Nov 13 '05 #3

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

Similar topics

3
1891
by: serge | last post by:
I am using SQL Server 7 SP4. I have created a blank database in which i am trying to import using DTS wizard all tables/views/stored procedures without any DATA (records). I keep getting different errors when importing the views and/or the SPs. I've tried many things unsuccessfully. Now even after the error msg of the DTS, i see some of the SPs under their previous names.
2
10408
by: John A. | last post by:
I've received this error several times, and have only been able to get around it by deleting the offending form(s) and importing them from backup - Here's the sequence: 1. I'm editing a form or code in a form module in MSAccess2000 on Win2k Terminal Server. 2. When I try to save, I get the "Save As" dialog box instead of a regular save. I click Cancel. I never know when this will occur, it's happened 3 or 4 times in 6 months.
3
4552
by: Danny | last post by:
Trying to import a couple of fields from an excel spreadsheet into an Access 2000 database by extracting needed fields and pasting them into a new spreadsheet, I can import the data into a new table in the database but will not allow me to import the same spreadsheet into an existing table w/ the same field properties. I know there's nothing wrong w/ the data because again it will allow me to import and create a new table w/ data, just...
1
2154
by: NathanB | last post by:
Hi there, I have a text file (flat file) which I would like to import on a regular basis into Access. The text file contains 2 record types, header (prefixed with RHD) and detail (prefixed with RDT). Each recordtype has a unique structure. ------------------------------------------------------------------------------- For example line one might read: RHD123456ABCDEF
11
4481
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
8
6474
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into usable data using more code. The problem I have is that the conversion of the text file, using a...
3
1855
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this one. I changed things around so much in the program that I'm lost on how to get it going again. I also blocked that part of the code off with delimiters; I didn't want it to interfere with program import java.awt.BorderLayout; import...
7
3472
by: thread | last post by:
Hi all i need to build progression calculator for a record and for this i need to have the possiblity to get the information for the previous record. is it posible to do it or i will need to use recordset for this?
4
3480
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields below. tblOrg OrgID, AutoNumber, PK ZipID, Number, FK tblState StateID, AutoNumber, PK
0
8105
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8565
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8246
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8415
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6076
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4045
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.