Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I use VB6.0 and Access

123 views
Skip to first unread message

diaExcel

unread,
Dec 21, 2007, 9:44:01 AM12/21/07
to
I want to put the data from an Excel file in an Access database using VB6.0
(ADO), how can I do that?

Thank you.

Alex Dybenko

unread,
Dec 23, 2007, 3:04:25 AM12/23/07
to
Hi,
here how you can automate excel
http://www.mvps.org/access/modules/mdl0006.htm

then you can use DAO to put data into appropriate tables

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"diaExcel" <diaE...@discussions.microsoft.com> wrote in message
news:A1D90004-B6A9-4C15...@microsoft.com...

Jamie Collins

unread,
Dec 24, 2007, 6:10:18 AM12/24/07
to
On Dec 23, 8:04 am, "Alex Dybenko"
<alex...@PLEASE.cemi.NO.rssi.SPAM.ru>

> >I want to put the data from an Excel file in an Access database using VB6.0
> > (ADO), how can I do that?
>
> here how you can automate excelhttp://www.mvps.org/access/modules/mdl0006.htm

>
> then you can use DAO to put data into appropriate tables

Which is worse: the OP posting an ADO question in the DAO group or
posting an DAO reply to an ADO question? ;-)

Jamie.

--

diaExcel

unread,
Dec 24, 2007, 12:13:00 PM12/24/07
to
Hi,

I want to import the Excel file in Access database using ADO in VB6.0, can I
do that and how?

Thank you.

"Alex Dybenko" a scris:

Alex Dybenko

unread,
Dec 24, 2007, 3:01:59 PM12/24/07
to
Well, no much difference DAO or ADO in this case, get a reference to excel,
open worksheet, open recordset to put data to, loop through required cells
and add records to recordset

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com

"diaExcel" <diaE...@discussions.microsoft.com> wrote in message

news:B6398DA3-7E0A-4778...@microsoft.com...

RoyVidar

unread,
Dec 25, 2007, 8:49:27 AM12/25/07
to
diaExcel wrote:
> Hi,
>
> I want to import the Excel file in Access database using ADO in VB6.0, can I
> do that and how?
>
> Thank you.

You can connect to the Excel file through ADO to retrieve the
information, given that the information is in some kind of order.
Here's some results of a short web search

http://www.ozgrid.com/forum/showthread.php?t=17158
http://support.microsoft.com/kb/326548/en-us
http://support.microsoft.com/kb/262537/en-us

Let's take it a step further. Say you've got the file xlsfile.xls
somewhere, where the headers are stuffed at the top of the sheet (sheet
named xlsfile, too), I think you should be able to do something like
this:

Dim cn As ADODB.Connection
Dim RecsAffected As Long
Dim SQLString As String

Set cn = New ADODB.Connection

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\<path and name of>.xls;" & _
"Extended Properties='Excel 8.0;HDR=Yes'"
cn.Open
SQLString = "INSERT INTO TargetTable In " & _
"'c:\<path and name of>.mdb' " & _
"SELECT * FROM [xlsfile]"
cn.Execute SQLString, RecsAffected, adCmdText + adExecuteNoRecords
Debug.Print RecsAffected

I think you can also be a bit selective with ranges, say

...SELECT * FROM [xlsfile$A1:X120]"

xlsfile here represenging sheet name.

--
Roy-Vidar

diaExcel

unread,
Dec 27, 2007, 9:47:01 AM12/27/07
to
Thank you so much!!!
I have another question....
in VB6.0 in a form I have a DataGrid which is populated with data from
Access, but now I want to add all rows from this datagrid in a different
table in Access, how can I do that, because I've seen that I have to add row
by row and I don't want to in that way, I want that all the rows in a single
step to be added...

Thank you

"RoyVidar" a scris:

louiss

unread,
Dec 29, 2007, 4:40:16 PM12/29/07
to
answer to your second question
i do it this way:
make a database in acces with the exact number of rows and form as you need
it
than select all the data you want to replace (use ctrl C)
go to the empty database and select all (left up) and do ctrl V
i use this methode to place excell data into acess database, it works perfekt
succes

diaExcel wrote:
>Thank you so much!!!
>I have another question....
>in VB6.0 in a form I have a DataGrid which is populated with data from
>Access, but now I want to add all rows from this datagrid in a different
>table in Access, how can I do that, because I've seen that I have to add row
>by row and I don't want to in that way, I want that all the rows in a single
>step to be added...
>
>Thank you
>
>"RoyVidar" a scris:
>

>> > Hi,
>> >
>[quoted text clipped - 37 lines]

louiss

unread,
Dec 29, 2007, 4:48:47 PM12/29/07
to
don't use vb 6 for this
make an empty acces database with the exact number of rows as you have in
excel
select all the data (in excel) you want to move (ctrl+C)
go to acces database en select all (upper left corner) and do ctrl+V
i use this methode on an database with 15.000 ithems on 29 rows - perfect
succes

RoyVidar

unread,
Dec 30, 2007, 6:32:30 AM12/30/07
to
on 27.12.2007, diaExcel supposed :

> Thank you so much!!!
> I have another question....
> in VB6.0 in a form I have a DataGrid which is populated with data
> from Access, but now I want to add all rows from this datagrid in a
> different table in Access, how can I do that, because I've seen that
> I have to add row by row and I don't want to in that way, I want
> that all the rows in a single step to be added...
>
> Thank you

[snipped stuff related to previous question]

Dear diaExcel,

though there probably are poeple frequenting this NG that are familiar
with objects of classic VB, I think you probably have better chances
of getting a reply in an NG dedicated to classic VB.

I don't know anything about the control you mention, as it doesn't
exist
in the product for which this NG is dedicated (Ms Access), but, say
you've populated it trough a select (apply WHERE clause as appropriate)

SELECT col1, col2, ...colN FROM SomeTable

you should be able to do something like (air code)

INSERT INTO NewTable
SELECT col1, col2, ...colN FROM SomeTable

- using the first select.

Or, to create a new table, something like

SELECT col1, col2, ...colN
INTO NewTable
FROM SomeTable

You should be able to fire some of this off on an ADO connection to
the db.

But adding redundant data etc, begs the question whether you've chosen
the most optimal design.

--
Roy-Vidar


0 new messages