close

Hello group,

I want to know the Code which exports data to an Access table
from an Excel worksheet and the code which imports data
from an Access table to a worksheet.

i want to run it as a macro .

Please help me with this problem.

cheers
Nuti
Hi

I am working on a webpage about this and hope to finish it next week

You can look here for information
www.erlandsendata.no/english/...php?t=envbadac

--
Regards Ron de Bruin
www.rondebruin.nlquot;nutiquot; gt; wrote in message ups.com...
gt; Hello group,
gt;
gt; I want to know the Code which exports data to an Access table
gt; from an Excel worksheet and the code which imports data
gt; from an Access table to a worksheet.
gt;
gt; i want to run it as a macro .
gt;
gt; Please help me with this problem.
gt;
gt; cheers
gt; Nuti
gt;
gt;
Hi Ron,

I have visited the link.
But it is throwing error.-----runtime error 3265

please help me out.

cheers,
nutiHave you set the reference in the VBA editor and are the File, Table and field names correct in the code

--
Regards Ron de Bruin
www.rondebruin.nlquot;nutiquot; gt; wrote in message oups.com...
gt; Hi Ron,
gt;
gt; I have visited the link.
gt; But it is throwing error.-----runtime error 3265
gt;
gt; please help me out.
gt;
gt; cheers,
gt; nuti
gt;
what shuold be the reference?

correct me if iam wrong---
---does the code take the excel sheet which is open/from the excel from
which the macro is run?gt; what shuold be the reference?

From the website :

The macro examples assumes that your VBA project has added a reference to the ADO object library.
You can do this from within the VBE by selecting the menu Tools, References and selecting Microsoft ActiveX Data Objects x.x Object
Library.
Use ADO if you can choose between ADO and DAO for data import or export.gt; correct me if iam wrong---
gt; ---does the code take the excel sheet which is open/from the excel from
gt; which the macro is run?

It use the active sheet but you can include the sheet name if you want

Range(quot;C1quot;)

' Example: ADOImportFromAccessTable quot;C:\FolderName\DataBaseName.mdbquot;, _
quot;TableNamequot;, Range(quot;C1quot;)
--
Regards Ron de Bruin
www.rondebruin.nlquot;nutiquot; gt; wrote in message ups.com...
gt; what shuold be the reference?
gt;
gt; correct me if iam wrong---
gt; ---does the code take the excel sheet which is open/from the excel from
gt; which the macro is run?
gt;
Hi Ron,

Actually i hav added the reference in the very begining.

the excel sheet has 7 columns....ServerName,PrinterName.......

when im running the debugger it is pointing to ---.Fields(quot;ServerNamequot;)
= Range(quot;Aquot; amp; r).Value

i had created a database by the name testaccess and tablename as
table1.

*******************************
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 1/4/2006 by Infosys
'

'

' exports data from the active worksheet to a table in an Access
database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open quot;Provider=Microsoft.Jet.OLEDB.4.0; quot; amp; _
quot;Data Source=E:\testaccess\testaccess.mdb;quot;
' open a recordset
Set rs = New ADODB.Recordset
rs.Open quot;Table1quot;, cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 2
' the start row in the worksheet
Do While Len(Range(quot;Aquot; amp; r).Formula) gt; 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields(quot;ServerNamequot;) = Range(quot;Aquot; amp; r).Value
.Fields(quot;PrinterNamequot;) = Range(quot;Bquot; amp; r).Value
.Fields(quot;ShareNamequot;) = Range(quot;Cquot; amp; r).Value
.Fields(quot;PortNamequot;) = Range(quot;Dquot; amp; r).Value
.Fields(quot;DriverNamequot;) = Range(quot;Equot; amp; r).Value
.Fields(quot;Commentquot;) = Range(quot;Equot; amp; r).Value
.Fields(quot;Locationquot;) = Range(quot;Equot; amp; r).Value
.Fields(quot;Sepfilequot;) = Range(quot;Equot; amp; r).Value

' add more fields if necessary...
.Update ' stores the new record
End With
r = r 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End SubRon,
read the range of the last three fields in sequence....shuold b
F,G,H..........Try to test it this evening

--
Regards Ron de Bruin
www.rondebruin.nlquot;nutiquot; gt; wrote in message ups.com...
gt; Ron,
gt; read the range of the last three fields in sequence....shuold b
gt; F,G,H..........
gt;
Hi Ron,

I have tried to run this macro (from the active excel sheet).
but it is throwing the same error.

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()