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.
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!
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]
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 :)
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.
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
Re: ADO error -- Object variable or With block variable not set
Quote:
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 :)
Re: ADO error -- Object variable or With block variable not set
Quote:
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.