Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Export data into Access Database

Hi
Is there a code which will allow me to click on a cmd button to add the
infromation shown in certain cells on the excel worksheet into an existing
Access Database to specific fields.

Thanks
Noemi
  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default Export data into Access Database

Yes the below uses DAO (you can use AODB also if your using a current version
of Office). Remeber to set the Reference to Microsoft DOA 3.6 in your
project. The Workspace code may vary with your version.

The example below takes data from E3, E4 and E5 and puts it into an Access
table with a primary key, if the record already exists it prompts for
overwrite. The below is basic but should get you started. The code is
attached to a button.

Private Sub CommandButton1_Click()
Dim wrkODBC As Workspace
Dim wrkJet As Workspace
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim ProdNo As Long
Dim Desc, ProdType As String
Dim Resp As Variant

ProdNo = Worksheets("Sheet1").Cells(3, 5).Value
Desc = Worksheets("Sheet1").Cells(4, 5).Value
ProdType = Worksheets("Sheet1").Cells(5, 5).Value

Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
Workspaces.Append wrkODBC
DefaultType = dbUseJet
Set wrkJet = CreateWorkspace("", "admin", "")
Set Db = wrkJet.OpenDatabase("C:\data\Db2.mdb")
Set Rs = Db.OpenRecordset("Products")
Rs.Index = "PrimaryKey"
Rs.Seek "=", ProdNo
If Rs.NoMatch Then
Rs.AddNew
Rs![Product No] = ProdNo
Rs![Desc] = Desc
Rs![Type] = ProdType
Rs.Update
Else
Resp = MsgBox("Item already exists - Update or Cancel", vbOKCancel)
If Resp = vbOK Then
Rs.Edit
Rs![Desc] = Desc
Rs![Type] = ProdType
Rs.Update
End If
End If
Rs.Close
Db.Close
wrkJet.Close
wrkODBC.Close
Set Rs = Nothing
Set Db = Nothing
Set wrkJet = Nothing
Set wrkODBC = Nothing
End Sub
--
Tony Green


"Noemi" wrote:

Hi
Is there a code which will allow me to click on a cmd button to add the
infromation shown in certain cells on the excel worksheet into an existing
Access Database to specific fields.

Thanks
Noemi

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
Macro to Export Selected fields to an Existing Access Database ernie Excel Programming 1 March 13th 06 05:01 PM
export data from MS Excel sheet to external database Mariusz[_2_] Excel Programming 2 March 29th 05 01:35 PM
export data from Excel to MS Access (ADO) using VBA Peter Brom Excel Programming 2 March 2nd 05 07:39 PM
From Excel 97 Programmatically create access 97 or 2000 database and export data to. [email protected] Excel Programming 0 December 23rd 04 10:44 PM
Export Data to Access Table Pete T[_2_] Excel Programming 1 October 10th 03 11:47 PM


All times are GMT +1. The time now is 08:16 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"