PC Review


Reply
Thread Tools Rate Thread

Open recordset using ODBC

 
 
=?Utf-8?B?TXIgQg==?=
Guest
Posts: n/a
 
      19th Apr 2006
The following code connects to an existing data source using and existing
ODBC connection when used in MS Access.

I am attempting to make the same connection from Excel, with one exception.
When used in an Access enviornment, the ODBC connection is used to link the
table. I can then use a different statement to actullay open the recordset.

I am getting an error at the "rstRecordset.Open" statement.

Here is the code:

Dim cnnConnect As ADODB.Connection
Dim rstRecordset As ADODB.Recordset


Set cnnConnect = New ADODB.Connection
cnnConnect = "ODBC;"
cnnConnect = cnnConnect & "DSN=ACCOUNTING;"
cnnConnect = cnnConnect & "APP=Microsoft Excel;"
cnnConnect = cnnConnect & "DATABASE=PHAGF;"
cnnConnect = cnnConnect & "UID=ACCTNG;"
cnnConnect = cnnConnect & "PWD=dtatrf;"
cnnConnect = cnnConnect & "TABLE=BPCSF_GPM"

Set rstRecordset = New ADODB.Recordset
strSql = "SELECT Max(BPCSF_GPM.PYEAR) AS MaxOfPYEAR FROM BPCSF_GPM " _
& "WHERE (((BPCSF_GPM.POPNCL)=""Y"") AND ((BPCSF_GPM.PAROFF)<21));"

rstRecordset.Open _
Source:=strSql, _
ActiveConnection:=cnnConnect, _
CursorType:=adOpenDynamic, _
LockType:=adLockReadOnly, _
Options:=adCmdText

varMaxYear = rstRecordset.Fields("MaxOfPYEAR").Value
rstRecordset.Close

Any assistance will be appreciated.

Mr. B
--
HTH

Mr B
 
Reply With Quote
 
 
 
 
MH
Guest
Posts: n/a
 
      19th Apr 2006
What is the error?

"Mr B" <(E-Mail Removed)> wrote in message
news59B7E84-5AD7-405A-A560-(E-Mail Removed)...
> The following code connects to an existing data source using and existing
> ODBC connection when used in MS Access.
>
> I am attempting to make the same connection from Excel, with one
> exception.
> When used in an Access enviornment, the ODBC connection is used to link
> the
> table. I can then use a different statement to actullay open the
> recordset.
>
> I am getting an error at the "rstRecordset.Open" statement.
>
> Here is the code:
>
> Dim cnnConnect As ADODB.Connection
> Dim rstRecordset As ADODB.Recordset
>
>
> Set cnnConnect = New ADODB.Connection
> cnnConnect = "ODBC;"
> cnnConnect = cnnConnect & "DSN=ACCOUNTING;"
> cnnConnect = cnnConnect & "APP=Microsoft Excel;"
> cnnConnect = cnnConnect & "DATABASE=PHAGF;"
> cnnConnect = cnnConnect & "UID=ACCTNG;"
> cnnConnect = cnnConnect & "PWD=dtatrf;"
> cnnConnect = cnnConnect & "TABLE=BPCSF_GPM"
>
> Set rstRecordset = New ADODB.Recordset
> strSql = "SELECT Max(BPCSF_GPM.PYEAR) AS MaxOfPYEAR FROM BPCSF_GPM " _
> & "WHERE (((BPCSF_GPM.POPNCL)=""Y"") AND ((BPCSF_GPM.PAROFF)<21));"
>
> rstRecordset.Open _
> Source:=strSql, _
> ActiveConnection:=cnnConnect, _
> CursorType:=adOpenDynamic, _
> LockType:=adLockReadOnly, _
> Options:=adCmdText
>
> varMaxYear = rstRecordset.Fields("MaxOfPYEAR").Value
> rstRecordset.Close
>
> Any assistance will be appreciated.
>
> Mr. B
> --
> HTH
>
> Mr B



 
Reply With Quote
 
 
 
 
=?Utf-8?B?TXIgQg==?=
Guest
Posts: n/a
 
      19th Apr 2006
The error is:
Application-defined or object-defined error

Mr B


"MH" wrote:

> What is the error?
>
> "Mr B" <(E-Mail Removed)> wrote in message
> news59B7E84-5AD7-405A-A560-(E-Mail Removed)...
> > The following code connects to an existing data source using and existing
> > ODBC connection when used in MS Access.
> >
> > I am attempting to make the same connection from Excel, with one
> > exception.
> > When used in an Access enviornment, the ODBC connection is used to link
> > the
> > table. I can then use a different statement to actullay open the
> > recordset.
> >
> > I am getting an error at the "rstRecordset.Open" statement.
> >
> > Here is the code:
> >
> > Dim cnnConnect As ADODB.Connection
> > Dim rstRecordset As ADODB.Recordset
> >
> >
> > Set cnnConnect = New ADODB.Connection
> > cnnConnect = "ODBC;"
> > cnnConnect = cnnConnect & "DSN=ACCOUNTING;"
> > cnnConnect = cnnConnect & "APP=Microsoft Excel;"
> > cnnConnect = cnnConnect & "DATABASE=PHAGF;"
> > cnnConnect = cnnConnect & "UID=ACCTNG;"
> > cnnConnect = cnnConnect & "PWD=dtatrf;"
> > cnnConnect = cnnConnect & "TABLE=BPCSF_GPM"
> >
> > Set rstRecordset = New ADODB.Recordset
> > strSql = "SELECT Max(BPCSF_GPM.PYEAR) AS MaxOfPYEAR FROM BPCSF_GPM " _
> > & "WHERE (((BPCSF_GPM.POPNCL)=""Y"") AND ((BPCSF_GPM.PAROFF)<21));"
> >
> > rstRecordset.Open _
> > Source:=strSql, _
> > ActiveConnection:=cnnConnect, _
> > CursorType:=adOpenDynamic, _
> > LockType:=adLockReadOnly, _
> > Options:=adCmdText
> >
> > varMaxYear = rstRecordset.Fields("MaxOfPYEAR").Value
> > rstRecordset.Close
> >
> > Any assistance will be appreciated.
> >
> > Mr. B
> > --
> > HTH
> >
> > Mr B

>
>
>

 
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
Open recordset fails with ODBC connection Amduke Microsoft Access VBA Modules 4 2nd Jul 2009 01:14 PM
How do you doubleclick on a recordset to open recordset in form vi =?Utf-8?B?Si4gS2VnZ2VybG9yZA==?= Microsoft Access Form Coding 3 4th May 2007 08:56 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer Microsoft ASP .NET 1 24th Mar 2006 05:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer Microsoft ASP .NET 0 24th Mar 2006 03:22 PM
Recordset: retrieve values from recordset using variable for field =?Utf-8?B?QW5uYSBT?= Microsoft Access VBA Modules 2 25th Oct 2004 07:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:26 PM.