|
-
Oct 30th, 2014, 12:47 PM
#23
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
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
|