Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Writting to tables in Access

I need to write and read data in an MSAccess mdb from Excel. I've tried
different variations of the "OpenDatabase" syntax to no avail. Do you have
an example of code that will enable me to write and read data from MSAccess
tables?

Catherine


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Writting to tables in Access

Here is some code for you. You just need to change the location of the
database, the table and the field names. This also requires a reference to
the ADO library which is added by doing the following:

In the checking in the VBA window Tools - References - Microsoft ADO ...

Private Const m_cDBLocation As String = "C:\Forecast.mdb"
Private Const m_cLogFile As String = "tblLogFile"

Public Sub LogIn()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset

' Open connection to the database
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & m_cDBLocation & ";"

rst.Open m_cLogFile, cnt, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
rst.AddNew

rst.Fields("User Name") = "Tada"
rst.Fields("In As") = "Shazam"
rst.Fields("Logged") = "Whoopee"
rst.Fields("Time") = Now()

rst.Update

' Close ADO objects
rst.Close
cnt.Close
Set rst = Nothing
Set cnt = Nothing
End Sub

Hope this helps...

"Catherine Benoit" wrote:

I need to write and read data in an MSAccess mdb from Excel. I've tried
different variations of the "OpenDatabase" syntax to no avail. Do you have
an example of code that will enable me to write and read data from MSAccess
tables?

Catherine



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Writting to tables in Access

http://www.erlandsendata.no/english/...php?t=envbadac

--
Regards,
Tom Ogilvy

"Catherine Benoit" wrote in message
...
I need to write and read data in an MSAccess mdb from Excel. I've tried
different variations of the "OpenDatabase" syntax to no avail. Do you have
an example of code that will enable me to write and read data from

MSAccess
tables?

Catherine




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing tables in access pm Excel Discussion (Misc queries) 1 June 5th 07 11:56 PM
VLOOKUP from Access Tables Mraggie Excel Discussion (Misc queries) 1 August 9th 06 09:33 PM
VLOOKUP from Access Tables Mraggie Excel Worksheet Functions 0 August 9th 06 08:36 PM
Access queries/tables Naz Excel Discussion (Misc queries) 1 July 5th 06 01:16 PM
Access tables in Excel widman Excel Discussion (Misc queries) 0 March 7th 06 08:26 PM


All times are GMT +1. The time now is 04:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"