Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2008, 11:35 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linking Access to Excel

Hi

I am a relative beginner to vba programming and am battling with connecting Access to excel using VBA.

My aim is to connect to my excel workbook and set the variable myVar equal to the value in my first cell.

I have been testing the following but cannot get it to work:

      Dim cnt As New ADODB.Connection
      Dim db As Database
      Set db = CurrentDb

      cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
               "Data Source= " & db

      Set xlApp = GetObject(, "Excel.Application")
    Set xlWb = GetObject("D:\DataPreparation\MetaData\Countries.x slx")
      Set xlWs = xlWb.Worksheets("Sheet1")

    myVar = xlWs.Cells(1, 1).Value




I get a type mismatch error at the Data source line.

I'm not sure if I'm going about this in the right way. I would appreciate it if someone could help me alter the above. If not please can you reccomend a new approach that would work.


Regards

Ryan







 
Old August 4th, 2008, 10:47 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

db is an object, of type Database. You cannot join an object to a string unless the object has a default property of type String (or another type than is automatically converted to a String, like an Integer, or a Single).





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking excel file to display messages from serve Kaustav Excel VBA 0 June 2nd, 2006 07:14 AM
Linking To Excel - Error timmaher Access 2 August 22nd, 2005 07:36 AM
Linking to Excel SS alantodd Access VBA 5 July 1st, 2005 02:34 PM
Linking to Excel Spreadsheet alantodd Access 0 June 28th, 2005 07:43 PM
Linking Outlook and Access John Anthony Access VBA 1 August 12th, 2003 10:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.