Re: ADO:VB6 Object not opened error. Guidance please?




<adalton@xxxxxxxxxxx> wrote in message news:ebg0et01hev@xxxxxxxxxxxxxxxxxxxx
Hello everyone! -

First off - I originally posted this in the
Comp.Lang.basic.viusal.database group.
I think I may have posted in the wrong group so I copied it here.. If I am
wrong, let
me know and I pologize in advance... Now.. Here goes -

I am exremely new to ADO (Ver 2.8). I'm a DAO 3.6 from old school and I
only have
I have 1 ADO book as a reference. I am not using an SQL server, or MySQL.

This is a subroutine of a larger program which is supposed to search a
field, within
a table, inside a database. (which I can't code until I can successfully
access the
database in the first place)

Using VB6 Enterprise, I am trying to open a Access database that I set up
as an
ODBC SQL as a System DSN called "MasterItemsDNS" in the system tab.

Now, it finds the MasterItemsDNS fine , but when the code executes, I get
a
'Operation not allowed when object is closed" error.
(Highlighted code that has the error is preceded by an arrow)

I realize I missed something here, but can not find it. I opened the
Database,
created the new recordset, and I think it was opened. But the proggie
says 'NO'


You have set a new recordset, you then need to open it with the data you
require using the connection you have made.
eg

Dim con As ADODB.Connection
Dim rst As ADODB.Recordset
Set con = New ADODB.Connection
Set rst = New ADODB.Recordset
'
con.Open "MasterItemsDNS"
rst.Open "SQL STRING", con, adOpenStatic 'select cursor type
'
If rst.Supports(adBookmark) Or rst.Supports(adApproxPosition) Then
NumRecords = rst.RecordCount
Else
'cursor type does not support record count
End If

'===========================================================================
=====
'DO STUFF

'===========================================================================
=====
'close rst & conn
rst.Close: Set rst = Nothing
con.Close: Set con = Nothing


.



Relevant Pages

  • Zusatz zu vorhergehender Nachricht
    ... die Ausgabe in der Schleife lautet folgendermassen(ohne "k-1", ... > Set con = New ADODB.Connection ... > Set rst = New ADODB.Recordset ... > Gruss und Danke! ...
    (microsoft.public.de.access)
  • Re: Accessing Excel to import Data into Access via ADO
    ... strSQL As String) ... Set con = New ADODB.Connection ... Set rst = New ADODB.Recordset ...
    (microsoft.public.access.macros)
  • Re: Accessing Excel to import Data into Access via ADO
    ... strSQL As String) ... Set con = New ADODB.Connection ... Set rst = New ADODB.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • Re: Please help with cmd.execute select SQL?
    ... What is the proper format for my SQL str using command.execute? ... I know I have matching data in my table, I keep coming up with a ... : Set con = Server.CreateObject ... : Set rst = Server.CreateObject ...
    (microsoft.public.inetserver.asp.general)
  • Please help with cmd.execute select SQL?
    ... What is the proper format for my SQL str using command.execute? ... I know I have matching data in my table, I keep coming up with a ... Set con = Server.CreateObject ... Set rst = Server.CreateObject ...
    (microsoft.public.inetserver.asp.general)