|
-
Feb 15th, 2001, 10:52 AM
#1
Thread Starter
Lively Member
Although I've used the adodc object before with no problems, I now receive a "Object variable or With block variable not set" error.
My References:
Microsoft ADO Ext 2.5 for DLL & security
Microsoft Data Binding Collection
Microsoft Data Environment Instance 1.0
Microsoft Jet and Replication Object 2.5 Library
(I will be accessing both Access & SQL 7 databases)
My Components:
Microsoft ADO Data Control 6.0
My ADO properties:
adoReports.CommandTimeout = 60
adoReports.CommandType = adCmdText
adoReports.ConnectionString = gconSwitch
adoReports.ConnectionTimeout = 60
adoReports.CursorLocation = adUseServer
adoReports.CursorType = adOpenStatic
adoReports.LockType = adLockReadOnly
adoReports.MaxRecords = 0
adoReports.Mode = adModeShareDenyNone
adoReports.RecordSource = "Select * from Clients"
gconSwitch = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Switch;Data Source=Server1"
I have tried changing properties and comparing properties with working code from other projects, to no avail.
I am beyond frustrated. I hope someone can help,
rlb_wpg
-
Feb 15th, 2001, 11:11 AM
#2
Hyperactive Member
You need to reference ADO itself, not just the extensibility library.
-
Feb 15th, 2001, 11:21 AM
#3
Thread Starter
Lively Member
In the "Available References" list, what is the reference name?
-
Feb 15th, 2001, 11:41 AM
#4
New Member
Try
Microsoft ActiveX Data Objects 2.x
-
Feb 15th, 2001, 11:45 AM
#5
Thread Starter
Lively Member
The library was included I missed typing in the list.
Thanks for replying.
Any other suggestions?
-
Feb 15th, 2001, 12:15 PM
#6
New Member
tell me
When do you get the aforementioned error?
-
Feb 15th, 2001, 12:25 PM
#7
Thread Starter
Lively Member
The first clue an error occurred was when the form
loaded the object was inaccessible, even though the
it was enabled.
To find the error, I placed the following code in the
Form_Load subroutine:
adoReports.Recordset.MoveFirst
-
Feb 16th, 2001, 06:41 AM
#8
Fanatic Member
Sounds like
The connection is failing (perhaps due to an invalid connection string) so therefore the data control is unable to instantiate it's recordset and hence the error you encountered.
Just to test it, in your Form_Load, instantiate and open a new connection object using the data control's connection string and see if that works. If it does, take the SQL string and open a recordset with it and see where you get to.
If the above works, you could try refreshing the data control when you open the form.
-
Feb 16th, 2001, 10:58 AM
#9
Thread Starter
Lively Member
Thanks for the reply.
Tested it, the connection string is fine.
Tested the sql statement also, it's fine.
It works fine when I create my own connection, command and recordset objects.
(dim cntTest as adodb.connection ... etc.)
Actually, that's what I've had to do considering I couldn't get the Adodc object to work.
I just would have preferred using the adodc object. Plus, it should work. I just don't get it.
-
Feb 16th, 2001, 11:07 AM
#10
Addicted Member
set
dim rst as new adodb.recordset
-
Feb 16th, 2001, 11:12 AM
#11
Fanatic Member
I don't think I can help then
I never used data bound controls anymore (the last time was with DAO) so I don't know what sort of problems could occur.
-
Feb 16th, 2001, 11:28 AM
#12
Hyperactive Member
Object Variable or With Variable
Souds like you forgot to instantiate the object...
For example, if your code looks something like this...
DIM rsRecords as RECORDSET
then you need to add the line:
SET rsRecords = NEW RECORDSET
This should fix the error you are getting.
Good luck!
-
Feb 16th, 2001, 11:37 AM
#13
Addicted Member
what does your actual code look like?
dim strConn as string, Conn as New adodb.connection
dim Rst as New adodb.recordset, strSQL as string
dim command as adodb.command
strConn = ado.ConnectionString 'ado = ado control
If conn.State = True Then
conn.Close
conn.Open strconn
Else
conn.Open strconn
End If
strSQL = "Select * from Clients"
With rst
.ActiveConnection = conn
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open Source:=strSQL
End With
The only time I've ever gotten the error you're getting is if my recordset or connection have not been referenced as either new, or part of another object.
-
Feb 16th, 2001, 11:39 AM
#14
Addicted Member
-
Feb 16th, 2001, 11:46 AM
#15
Member
Don't use the ADO control
I tried to use it, for opening up an Excell spreadsheet, to no avail. (I can't remember the problem, but I spent a whole day on it trying to resolve it).
Finally, I gave up, threw away the ADO data control, use the Connection and Recordset objects, and had my project finished in 15 minutes.
Samwise Galenorn
[email protected]
-
Feb 16th, 2001, 12:38 PM
#16
Hyperactive Member
One thing I forgot!
Very important!!
When you are done with the recordset, make sure free the resources.
SET rsRecords = NOTHING
If you do not do this, then everytime you execute the function to build the recordset it will build a new one and still hold your old ones in memory. You will quickly run out of resources.
-
Sep 28th, 2001, 12:58 PM
#17
New Member
Refresh
If you set up the ConnectionString and RecordSource properties correctly, the first thing you should do in your code is:
ADODC.Refresh
I think this is basically like the Open property for ADODB.
-
Feb 18th, 2002, 07:17 PM
#18
New Member
adodc error
I encountered the same error when I moved my program to a test machine. I suspected that the test machine was running a different mdac version than the development machine. I updated it to mdac 2.5 and it fixed the problem.
-
Oct 30th, 2014, 08:36 AM
#19
Lively Member
Re: ADO error -- Object variable or With block variable not set
Sorry for this... I know this topic is about 12 year ago. but i have posted under this topic because:
1) this important question is on top of google search results
2) there is no any correct answer in this topic!
i have tested this:
this error can be for the following reason:
if you use a variable (ADODB.connection type) as an argument in a sub or function, after executing the ADODB open command line, you'll get this error:
Object variable or With block variable not set
to avoid this error, you need to define the ADODB.connection variables as a public variable in your program not an argument
this was my experience
i hope it can help you
-
Oct 30th, 2014, 10:09 AM
#20
Re: ADO error -- Object variable or With block variable not set
Hey, the moderator may close it on you, but I love it when an old thread becomes active and the thread starter re-posts, showing he/she is still out there.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Oct 30th, 2014, 12:09 PM
#21
Re: ADO error -- Object variable or With block variable not set
@Mehdi Jazini - can you give an example of what you are talking about? From what I'm reading it sounds like you think this should cause an error but I don't see it that way.
Code:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=MARKPC"
cn.Open
Set rs = GetRecords(cn)
End Sub
Private Function GetRecords(ByVal cn As ADODB.Connection) As ADODB.Recordset
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.Source = "Select * From Employees"
.Open
End With
Set GetRecords = rs
End Function
-
Oct 30th, 2014, 12:47 PM
#22
Lively Member
Re: ADO error -- Object variable or With block variable not set
 Originally Posted by MarkT
@Mehdi Jazini - can you give an example of what you are talking about? From what I'm reading it sounds like you think this should cause an error but I don't see it that way.
Code:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=MARKPC"
cn.Open
Set rs = GetRecords(cn)
End Sub
Private Function GetRecords(ByVal cn As ADODB.Connection) As ADODB.Recordset
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.ActiveConnection = cn
.Source = "Select * From Employees"
.Open
End With
Set GetRecords = rs
End Function
1 hour ago i have changed my code in my program. but i remember the ADODB.Connection argument was ByRef not ByVal
it seems the error is in ByRef mode
i have used ByRef because i wanted to use its argument out of the function too
i didn't know that
thank you for your info
-
Oct 30th, 2014, 01:07 PM
#23
Re: ADO error -- Object variable or With block variable not set
 Originally Posted by Elroy
Hey, the moderator may close it on you, but I love it when an old thread becomes active and the thread starter re-posts, showing he/she is still out there.
Yeah, I noticed the moderator is pretty zealous about closing old threads that are resurfacing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|