PC Review


Reply
Thread Tools Rate Thread

Connecting to Access

 
 
MikeH2
Guest
Posts: n/a
 
      23rd Jan 2008
I am trying these commands:
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=" &
DataS
Set rs = New ADODB.Recordset
rs.Open "Transfers", cn, adOpenKeyset, adLockOptimistic,
adCmdTable
Sometimes It works and in another module on another spreadsheet, I get a
compile error: User-Defined Type not Defined and it highlights the cn As
ADODB.Connection on the first line. Why do I get two different situations.
I think my code is pretty much the same otherwise. I did the one that works
several months ago and the new code just today and I can't find any
difference! Ideas?
 
Reply With Quote
 
 
 
 
SeanC UK
Guest
Posts: n/a
 
      23rd Jan 2008
Hi Mike,

One thing you can check is that in each spreadsheet in which you are using
the code, the correct Library has been refernced for using ADODB. If you have
copied modules or code from one spreadsheet to the next then the copied
versions will not have the relevant references. In the VBE goto Tools >>
References and make sure one of the Microsoft ActiveX Data Object libraries,
or equivalent, is being referenced.

I imagine that is the problem.

Hope this helps,

Sean.
--
(please remember to click yes if replies you receive are helpful to you)


"MikeH2" wrote:

> I am trying these commands:
> Dim cn As ADODB.Connection, rs As ADODB.Recordset
> Set cn = New ADODB.Connection
> cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=" &
> DataS
> Set rs = New ADODB.Recordset
> rs.Open "Transfers", cn, adOpenKeyset, adLockOptimistic,
> adCmdTable
> Sometimes It works and in another module on another spreadsheet, I get a
> compile error: User-Defined Type not Defined and it highlights the cn As
> ADODB.Connection on the first line. Why do I get two different situations.
> I think my code is pretty much the same otherwise. I did the one that works
> several months ago and the new code just today and I can't find any
> difference! Ideas?

 
Reply With Quote
 
Conan Kelly
Guest
Posts: n/a
 
      23rd Jan 2008
MikeH2,

I'm guessing you are missing a reference to one of the ADO libraries.

In the VBE, make sure you have an object/item from your problematic workbook
selected in the project explorer. Then Tools > References..., then scroll
through the list for Microsoft ActiveX Data Objects #.# Library and put a
check mark in the check box. I'm not sure which one will work best for
you...I'd just select the highest version.

HTH,

Conan





"MikeH2" <(E-Mail Removed)> wrote in message
news:8450DCCC-D874-44C4-B85F-(E-Mail Removed)...
>I am trying these commands:
> Dim cn As ADODB.Connection, rs As ADODB.Recordset
> Set cn = New ADODB.Connection
> cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=" &
> DataS
> Set rs = New ADODB.Recordset
> rs.Open "Transfers", cn, adOpenKeyset, adLockOptimistic,
> adCmdTable
> Sometimes It works and in another module on another spreadsheet, I get a
> compile error: User-Defined Type not Defined and it highlights the cn As
> ADODB.Connection on the first line. Why do I get two different
> situations.
> I think my code is pretty much the same otherwise. I did the one that
> works
> several months ago and the new code just today and I can't find any
> difference! Ideas?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in connecting to MS Access phong.lee@gmail.com Microsoft Excel Programming 1 27th Sep 2007 08:24 PM
Re: Connecting to access Peter T Microsoft Excel Programming 1 8th Jun 2005 02:20 PM
Connecting to access Justin Busch Microsoft VB .NET 2 1st Oct 2004 04:09 PM
connecting to access from the web Andy Levy Microsoft Access 0 26th Apr 2004 12:47 PM
MS Access 97 Connecting to MS SQL Phichai Microsoft Access ADP SQL Server 1 29th Dec 2003 12:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 PM.