LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default New record in table in Access from VBA in Excel

I have an excel file that that a customer uses to order product. I can have
up to 40 different files at on time. (eg. order1.xls,
order2.xls,..order40.xls) I have an Access database that I use to track jobs
at the shop that take the orders. I wouls like to place a button on the excel
sheet that when clicked would run code that would:

1. Open a new record in table "jobs" in acces.
2. Place information from the excel file into certain fields in the table.
(eg. order1.xls, cell C2=11252. I would like to place the following
info in field "description" in table "jobs" - "Vehicle# 11252"")
3. Place value from field "JobNumber" in table "jobs" into cell D1 on
order1.xls.

I have little experience with interapplication code. I copied and tried this
from a web page but it does not work:

Sub MakeJob()
' 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 "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\Documents_ and Settings\jeremy.CREEDBILT\My Documents\Test Job.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Jobs", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
With rs
.AddNew ' create a new record
' add values to each field in the record
.fields("Date") = Now()
If Range("a2") = "chevrolet" Then
.fields("Customer") = "Courtesy Chevrolet"
Else
.fields("Customer") = "Five Star Ford"
End If
.fields("Description") = "Accessories for Pick up, APS veh# " &
Range _("A1").Value
' add more fields if necessary...
.Update ' stores the new record
End With
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub

This code is one I am using on a sample DB until I get the code figured
right. Cell references might be different. I get this error when I try to run
the code:

Compile error:
User-define type not defined.
and this part of the code is highlighted:
cn As ADODB.Connection

Can anyone help me with the code for this project?

 
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
How do I Consolidate an EXCEL Report into a record for ACCESS impo Mike M Excel Discussion (Misc queries) 1 September 16th 09 11:28 AM
Export Single Record to Append to Access Table RMS Excel Discussion (Misc queries) 1 December 9th 08 07:08 PM
Obtaining a single Access record from Excel input travis Links and Linking in Excel 5 November 23rd 05 09:02 AM
How can I update an MS Access table record from within Execl works David Canfield Excel Discussion (Misc queries) 0 January 14th 05 08:51 PM
Modifying an Access record in Excel John Moll Excel Programming 1 August 1st 03 05:27 PM


All times are GMT +1. The time now is 01:35 PM.

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

About Us

"It's about Microsoft Excel"