Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I Consolidate an EXCEL Report into a record for ACCESS impo | Excel Discussion (Misc queries) | |||
Export Single Record to Append to Access Table | Excel Discussion (Misc queries) | |||
Obtaining a single Access record from Excel input | Links and Linking in Excel | |||
How can I update an MS Access table record from within Execl works | Excel Discussion (Misc queries) | |||
Modifying an Access record in Excel | Excel Programming |