Advertisement

11.11.2005 at 09:30AM PST, ID: 21627956
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

VBA code to have Excel insert records into Access Database
Tags: vba, excel, insert, access, database
I'm a newie in the Access world, so I need a little "push" to get me in the right direction.  What I'm wanting to do is build an Excel spreadsheet that will ask the user a series of questions ( some of which will be yes/no message box, and some of which will be from a input box that the user will have to type in a text string ( comments ) ).

When the user is completed with the series of questions, I would like to have Excel insert that data as a record in a pre-built Access Database.

Example
Input Box = user enters "48825"
Message Box = user selects "Yes"
Input Box = user enters "00013469568"
Input Box = user enters "all orders were OK"

After the user enters the last input box, Excel will then enter the data into the Access Database like below

Route            Check_in               Invoice Number            Comments
48825               Yes                     00013469568             all orders were OK

I was thinking about having each answer put in row 1 and then when the questions are complete have Excel insert row 1 into the Access Database.

Thanks

Andrew
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: awehme
Solution Provided By: XL-Dennis
Participating Experts: 4
Solution Grade: A
Views: 763
Translate:
Loading Advertisement...
11.11.2005 at 09:37AM PST, ID: 15275270

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 09:40AM PST, ID: 15275291

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 09:54AM PST, ID: 15275407

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 09:56AM PST, ID: 15275423

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 10:06AM PST, ID: 15275514

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 10:37AM PST, ID: 15275779

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 10:49AM PST, ID: 15275866

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 10:49AM PST, ID: 15275873

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 11:06AM PST, ID: 15276033

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.11.2005 at 11:19AM PST, ID: 15276126

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 05:53AM PST, ID: 15319423

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 06:42AM PST, ID: 15319814

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 07:06AM PST, ID: 15319983

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 07:11AM PST, ID: 15320030

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 08:08AM PST, ID: 15320619

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
11.18.2005 at 08:22AM PST, ID: 15320757

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
11.11.2005 at 09:37AM PST, ID: 15275270

Rank: Genius

The following sample code illustrates how to:

   -> open a database connection
   -> open a recordset
   -> use a stored procedure to perform a query
   -> build a custom query
   -> check for an empty recordset
   -> read all records in a recordset
   -> add a record to a recordset
   -> delete a record from a recordset
   -> close a recordset and database

This sample code, except for Open database method, can be used with any database such as Access or SQL Server. When using a database, most interaction happens via a recordset. Data is manipulated almost entirely using Recordset objects. Any number of Recordset objects can be created and used at the same time - each representing a different query or the same query. Different Recordset objects can access the same tables, queries, and fields without conflicting.

After opening a Recordset the Recordset can contain zero or more records. One record in the Recordset is always the current record except when the Recordset BOF or EOF property is true in which case no record is the current record. The current record is the record that is affected by any record-specific methods. To move amongst the records in a Recordset use the MoveNext, MovePrevious, MoveLast, and MoveFirst Recordset methods. A specific record can be made the current record by setting the AbsolutePosition property to the index number of the desired record. Fields in the current record are access as follows:

   Value = MyRecordset!Field1
   MyRecordset!Field2 = Value + 1

When the current record is changed use the Update Recordset method to apply the changes to the database. Use the Add method to add a new record and teh Delete method to delete the current record.

Before writing any ADODB code the following references need to be referenced in the VBA project (Tools->References):

   Microsoft ActiveX Data Objects x.x Library
   Microsoft ActiveX Data Objects Recordset x.x Library

For additional information on the ADODB interface see the MSDN pages at:

   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstdatatypeenum.asp

Sample code:

   Dim MyDatabase As ADODB.Connection
   Dim MyCommand As New ADODB.Command
   Dim MyRecordset As New ADODB.RecordSet
   
   ' Open database connection
   Set MyDatabase = New ADODB.Connection
   MyDatabase.CursorLocation = adUseClient
   MyDatabase.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\full\path\to\database.mdb'; User Id=admin; Password=;"
   ' For more information about Open syntax:
   '   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadomethods.asp
   '   and navigate to Open Method (ADO Connection)
   '   Additional help can be found at http://www.connectionstrings.com/

   ' Query database using stored procedure
   Set MyCommand.ActiveConnection = MyDatabase
   MyCommand.CommandText = "qrySomeQuery" ' <- name of procedure
   MyCommand.CommandType = adCmdStoredProc
   With MyCommand
      .Parameters.Refresh
      .Parameters.Append .CreateParameter("QueryTextParam", adVarChar, adParamInput, 10, "Value")
      .Parameters.Append .CreateParameter("QueryLongParam", adBigInt, adParamInput, , LongValue)
      .Parameters.Append .CreateParameter("QueryDateParam", adDate, adParamInput, , DateValue)
      .Parameters.Append .CreateParameter("QueryDateTimeStampParam", adDBTimeStamp, adParamInput, , DateTimeValue)
      .Parameters.Append .CreateParameter("BooleanParam", adBoolean, adParamInput, , BooleanValue)
      ' For more information about CreateParameter syntax:
      '   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadomethods.asp
      '   and navigate to CreateParameter Method
   End With
   
   ' Open recordset
   MyRecordset.Open MyCommand, , adOpenDynamic, adLockPessimistic
   ' For more information about Open method syntax:
   '   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadomethods.asp
   '   and navigate to Open Method (ADO Recordset)
   
   ' Test for no records
   If MyRecordset.BOF And MyRecordset.EOF Then
      MsgBox "No records returned"
   End If
   
   ' Look at all records in record set
   While Not MyRecordset.EOF
      MsgBox "Record number: " & MyRecordset.AbsolutePosition
      MyRecordset.MoveNext
   Wend
   
   ' Update current record
   MyRecordset!Field1 = "Some data"
   MyRecordset!Field2 = "Some more data"
   MyRecordset.Update

   ' Move current record to worksheet
   With Sheets("Sheet1")
      Cells(Row, "A") = MyRecordset!Field1
      Cells(Row, "B") = MyRecordset!Field2
   End With
   
   ' Add new record
   MyRecordset.AddNew
   MyRecordset!Field1 = "Some data"
   MyRecordset.Update
   
   ' Delete current record
   MyRecordset.Delete
   
   ' Close recordset
   MyRecordset.Close
   
   ' Build custom query
   With RecordSetCommand
      Set .ActiveConnection = Database
      .CommandType = adCmdText
      .CommandText = "Select * From tblMyTable WHERE (tblMyTable.MyID = 1)"
   End With
   RecordSet.Open RecordSetCommand, , adOpenDynamic, adLockPessimistic
   
   ' Close database
   MyDatabase.Close

Kevin
Assisted Solution
 
11.11.2005 at 09:40AM PST, ID: 15275291

Rank: Genius

Here is sample code more specific to your situation:

Public Sub AddRecord(ByVal SourceSheet As Worksheet, ByVal Row As Long)

   Dim MyDatabase As ADODB.Connection
   Dim MyCommand As New ADODB.Command
   Dim MyRecordset As New ADODB.Recordset
   
   ' Open database connection
   Set MyDatabase = New ADODB.Connection
   MyDatabase.CursorLocation = adUseClient
   MyDatabase.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\full\path\to\database.mdb'; User Id=admin; Password=;"
   ' For more information about Open syntax:
   '   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadomethods.asp
   '   and navigate to Open Method (ADO Connection)
   '   Additional help can be found at http://www.connectionstrings.com/
   
   ' Open recordset
   MyRecordset.Open MyCommand, , adOpenDynamic, adLockPessimistic
   ' For more information about Open method syntax:
   '   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadomethods.asp
   '   and navigate to Open Method (ADO Recordset)
   
   ' Add new record
   MyRecordset.AddNew
   MyRecordset!Field1 = SourceSheet.Cells(Row, "A")
   MyRecordset!Field2 = SourceSheet.Cells(Row, "B")
   MyRecordset.Update
   
   ' Close recordset
   MyRecordset.Close
   
   ' Close database
   MyDatabase.Close
   
End Sub

Kevin
 
11.11.2005 at 09:54AM PST, ID: 15275407
It would be a *lot* less work and less complicated to build a simple form in your existing DB or to create a form using InfoPath.

The Access steps would be:
1. If one doesn't already exist, create a query that selects the items you wish to update.
2. Open the Form Wizard and base the forms recordsource on the query
3. Modify form to meet your organizational design standards or just make it look pretty
4. Change the form Data-->Data Entry in Properties to "Yes"
5. Save/re-Distribute db

The InfoPath steps would be:
1. If one doesn't already exist, create a query that selects the items you wish to update.
2. Create a new form in InfoPath and follow the db connection wizard steps to connect to your db and select your query from step 1 above as your datasource.
3. Drag/Drop fields from query into form
4. Add a submit button.
5. Save/distribute form

While it definitely *can* be done with Excel, it just seems to me that it's the wrong tool for the task at hand.
Assisted Solution
 
11.11.2005 at 09:56AM PST, ID: 15275423

Rank: Master

Another alternative would be to Execute a sql query

have an insert statement like:

With WorkSheets(1)
     strSQL = "INSERT INTO tblYourAccessTable ( all, of, your, database, field, names) Values ( " & .Range("A5")  & ", " & .Range("B5") & ...(etc.) ")"
End With

You have your sql string for that row.

Then you can insert it on a new row

YourConnection.Execute strSQL


One thing you might remember with this is that if there is already data there, it will not update it.  There will be an error if your putting in duplicate information.  (with either way i believe) remember to update or delete it first if you know that data exists for that record.

I hope this helps,

Kelvin
Assisted Solution
 
11.11.2005 at 10:06AM PST, ID: 15275514

Rank: Genius

AJ is right to some degree. However, Access installations are far less than Excel and Excel's UI environment is more easy to control than the Access UI environment from a VBA perspective. In short Excel is more portable and user friendly. As long as you have a network connection and an installation of Excel you can use Excel to do the deed.

Kevin
 
11.11.2005 at 10:37AM PST, ID: 15275779

Rank: Guru

Hi all and especially Andrew!

Below You find a workable solution for You and don't forget to add a reference to the Microsoft Active X object Library via Tools | References... in the VB-editor.

Option Explicit

Const stDB As String = "c:\XLDennis.mdb"

Const stCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & stDB & ";"

Sub Add_Data_To_Access_Database()
Dim cnt As ADODB.Connection
Dim stSQL As String

Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim rnData As Range

Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(1)

With wsSheet
    'Range in the source worksheet
    Set rnData = .Range("A1:D1")
End With

'Instantiate the ADODB-object.
Set cnt = New ADODB.Connection

'The SQL-statement to insert values in the table.
stSQL = "INSERT INTO Table_Name (Route,Check_In,Invoice_Number,Comments) VALUES('" & _
       rnData(1, 1).Value & "','" & rnData(1, 2).Value & "','" & rnData(1, 3).Value & "','" & rnData(1, 4).Value & "');"

With cnt
    'Open the connection
    .Open stCon
    'Insert the values
    .Execute (stSQL)
    'Close the connection
    .Close
End With

'Release objects from memory
Set cnt = Nothing

'Delete the added values from the soure worksheet
rnData.ClearContents

End Sub

ajkamp,
Although I can agree in general terms there are some circumstances that force many users to use tools like Excel. The primary reason is that they don't have access to MS Access or InfoPath or...

Except for that keep in mind that this is a core Excel-forum ;-)

Kind regards,
Dennis
Accepted Solution
 
11.11.2005 at 10:49AM PST, ID: 15275866

Rank: Genius

Dennis,

I have always preferred ADODB objects and methods over SQL commands as it seems easier to code. There are exceptions, of course, such as when building more complex queries from a variety of criteria inputs. Are there any specific reasons you choose to use SQL statements for more mundane transactions that can just as easily be done using ADODB methods?

Kevin
 
11.11.2005 at 10:49AM PST, ID: 15275873
Don't get me wrong, I love Excel :)

I feel that even though this is an Excel forum, it may be helpful to the requestor to offer alternatives if they are easy, workable solutions that involve less work to implement.
 
11.11.2005 at 11:06AM PST, ID: 15276033

Rank: Genius

Absolutely! Dennis and I are only offering the counter viewpoint to complete the perspective.

Another consideration that I didn't mention that is unique to this case is the asker is an Access neophyte which makes the move to an Access-only solution pretty scary.

Kevin
 
11.11.2005 at 11:19AM PST, ID: 15276126

Rank: Guru

ajkamp,

You're most welcome with different alternatives and personal I appreciate diversity :-)

I would love to see a full example of it with InfoPath as I got it but never use it...

I has a local close friend, who works with SQL Server administration for a worldwide company and tries to learn me more about it. He has influenced me in the use of SQL-statements as they provide us with a flexibility that the built-in options do not. Yes, the SQL-statements can be both lenghty and messy but the benefit of the use of the Execute-statement override it in my opinion.

Kind regards,
Dennis


 
11.18.2005 at 05:53AM PST, ID: 15319423
Thanks for all for pushing me in the right direction. I have come up with the following sub that works great.  Since writing the question, I have come up with a better way of what I what to get done in the spreadsheet that I am building, thus the reason why my macro doesn't really answer the question, but surely give me the "idea or know how" on how to do it now, so I can tweak it any way I please.

Thanks

Sub Export_Employee_List()

Dim rsemployee As DAO.Recordset
Set db = Workspaces(0).OpenDatabase(DB_NAME)
Set rs = db.OpenRecordset("employee_list", dbOpenDynaset)

Dim startrow As Long
Dim endrow As Long
Dim irow As Long
Dim icol As Integer

    strSQL = "DELETE * FROM employee_list"
    db.Execute strSQL

Sheet4.Activate
startrow = 2
endrow = Sheet4.UsedRange.Rows.Count

For irow = startrow To endrow

    rs.AddNew
   
    For icol = 0 To rs.Fields.Count - 1
        rs(icol) = Cells(irow, icol + 1)
    Next icol
   
    rs.Update
   
Next irow

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing

End Sub
 
11.18.2005 at 06:42AM PST, ID: 15319814

Rank: Guru

Hi and thanks for grade.

I'm curious about why You ended up with DAO and not ADO?

Kind regards,
Dennis
 
11.18.2005 at 07:06AM PST, ID: 15319983
I looked at some spreadsheets that some of my co-workers had and their code had DAO.

Is one better then other.??  Or is it like Ford / Chevy.
 
11.18.2005 at 07:11AM PST, ID: 15320030

Rank: Guru

When it comes to Access and Excel it's preferable to use DAO as unlike ADO DAO explicit target Access.

Honestly for the average user it's like Volvo / Saab (I live in Sweden!)

Kind regards,
Dennis

 
11.18.2005 at 08:08AM PST, ID: 15320619
That's pretty funny Dennis :)
 
11.18.2005 at 08:22AM PST, ID: 15320757

Rank: Guru

Yes - both cartypes and DAO/ADO :-) :-)

Have a nice weekend and all the very best from,
Dennis
 
 
20080236-EE-VQP-29