﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>A1VBCode Forums / Classic Visual Basic (VB 6 or earlier) / VBA(Excel, Word, etc...)  / Problems running VBA code within Excel / Latest Posts</title><generator>InstantForum.NET v4.1.1</generator><description>A1VBCode Forums</description><link>http://www.a1vbcode.com/vbforums/</link><webMaster>forums@a1vbcode.com</webMaster><lastBuildDate>Thu, 09 Feb 2012 04:39:37 GMT</lastBuildDate><ttl>20</ttl><item><title>Problems running VBA code within Excel</title><link>http://www.a1vbcode.com/vbforums/Topic28892-14-1.aspx</link><description>Have created the following code to export Excel worksheet data to Access database. Had early issues with registering type to allow system to recognize the Dim statement. Setup object library to include Microsoft DAO 3.6 Object Library, but now when trying to compile macro I get a runtime error '429' that an ActiveX component can't create object on the Set db statement of the code. What am I missing?&lt;/P&gt;&lt;P&gt;Sub DAOFromExcelToAccess()&lt;BR&gt;'exports data from the active worksheet to a table in an Access database&lt;BR&gt;'this procedure must be edited before use&lt;BR&gt;Dim db As Database, rs As Recordset, r As Long&lt;BR&gt;&lt;FONT style="BACKGROUND-COLOR: #dddd33"&gt;Set db = OpenDatabase("C:\Documents and Settings\sward\My Documents\Austell Equipment\GM-130\Productivity Reports\Machine_Logging.mdb")&lt;BR&gt;&lt;/FONT&gt;'open the database&lt;BR&gt;Set rs = db.OpenRecordset("GM130", dbOpenTable)&lt;BR&gt;'get all records in a table&lt;BR&gt;r = 1 'the start row in the worksheet&lt;BR&gt;Do While Len(Range("A" &amp;amp; r).Formula) &amp;gt; 0&lt;BR&gt;'repeat until first empty cell in column A&lt;BR&gt;With rs&lt;BR&gt;.AddNew 'create a new record&lt;BR&gt;'add values to each field in the record&lt;BR&gt;.Fields("Customer") = Range("A" &amp;amp; r).Value&lt;BR&gt;.Fields("Metallizer") = Range("B" &amp;amp; r).Value&lt;BR&gt;.Fields("Met_Date") = Range("C" &amp;amp; r).Value&lt;BR&gt;.Fields("Vac_Roll_Number") = Range("D" &amp;amp; r).Value&lt;BR&gt;.Fields("Met_Quality") = Range("E" &amp;amp; r).Value&lt;BR&gt;.Fields("Met_Performance") = Range("F" &amp;amp; r).Value&lt;BR&gt;.Fields("Met_Downtime") = Range("G" &amp;amp; r).Value&lt;BR&gt;.Fields("Slitter") = Range("H" &amp;amp; r).Value&lt;BR&gt;.Fields("Slit_Date") = Range("I" &amp;amp; r).Value&lt;BR&gt;.Fields("Slit_Quality") = Range("J" &amp;amp; r).Value&lt;BR&gt;.Fields("Slit_Performance") = Range("K" &amp;amp; r).Value&lt;BR&gt;.Fields("Slit_Downtime") = Range("L" &amp;amp; r).Value&lt;BR&gt;'add more fields if necessary...&lt;BR&gt;.Update 'store the new record&lt;BR&gt;End With&lt;BR&gt;r = r + 1 'next row&lt;BR&gt;Loop&lt;BR&gt;rs.Close&lt;BR&gt;Set rs = Nothing&lt;BR&gt;db.Close&lt;BR&gt;Set db = Nothing&lt;/P&gt;&lt;P&gt;End Sub&lt;BR&gt;</description><pubDate>Mon, 15 Feb 2010 11:17:24 GMT</pubDate><dc:creator>sclward</dc:creator></item></channel></rss>
