Nelmarcas
asked on
Object Variable or With Block Dilema!!!
When I run my Visual Basic Project after running with a full compile everything works fine. But, when I make a EXE and run it it comes back and tells me that the Object Variable or WIth Block variable is not set. Why here and not after I compile. How am I suppsoe to debug this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Run the application in VB again and try to recreate the exact spot where the error occurs. You may find that you are missing an object declaration somewhere after all. Compilation does not necessarily catch all errors, if it did there would be no such thing as run-time erros in VB.
ASKER
True.
The error still occured after I made sure that the Option Explicit Statement was at the head of all my objects.
Unfortunately this is where it happened:
Public Function Add(TheContainer As Object) As Long
Dim ps As rdoQuery
Dim rs As rdoResultset
Dim SQL As String
Dim RetCode As Long
Dim TheAddressID As Long
On Error GoTo AddressAddError
ReturnCode = 0
Screen.MousePointer = vbHourglass
SQL = " execute Global..Add_Address " & _
" 0 ," & _
" 'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , "
SQL = SQL & "'Ad' , " & _
"'Adding' , " & _
"'Add' , " & _
"'Add' , " & _
"'XXX' "
Set ps = Rover.TheConnection.Create PreparedSt atement("M yPs", SQL)
ps.RowsetSize = 1
Set rs = ps.OpenResultset(rdOpenFor wardOnly)
TheAddressID = rs(0)'HERE!!!!!!!
'here is where I get the error that the Object Collection: Couldn't find item indicated by text occurs. Funny it runs on my workstation just fine. But On my partners it coughs. ANy ideas???
rs.Close
ps.Close
'Rover.TheConnection.rdoQu ery("MyPs" ).Close
RetCode = Edit(TheAddressID, TheContainer)
If RetCode Then
Add = TheAddressID
Else
Add = 0
End If
Screen.MousePointer = vbDefault
Exit Function
AddressAddError:
Rover.CBPErr.Number = Err.Number
Select Case Rover.CBPErr.Action
Case vbAbort
Add = False
Exit Function
Case vbRetry
Resume
Case Else
Resume Next
End Select
End Function
The error still occured after I made sure that the Option Explicit Statement was at the head of all my objects.
Unfortunately this is where it happened:
Public Function Add(TheContainer As Object) As Long
Dim ps As rdoQuery
Dim rs As rdoResultset
Dim SQL As String
Dim RetCode As Long
Dim TheAddressID As Long
On Error GoTo AddressAddError
ReturnCode = 0
Screen.MousePointer = vbHourglass
SQL = " execute Global..Add_Address " & _
" 0 ," & _
" 'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , " & _
"'Adding' , "
SQL = SQL & "'Ad' , " & _
"'Adding' , " & _
"'Add' , " & _
"'Add' , " & _
"'XXX' "
Set ps = Rover.TheConnection.Create
ps.RowsetSize = 1
Set rs = ps.OpenResultset(rdOpenFor
TheAddressID = rs(0)'HERE!!!!!!!
'here is where I get the error that the Object Collection: Couldn't find item indicated by text occurs. Funny it runs on my workstation just fine. But On my partners it coughs. ANy ideas???
rs.Close
ps.Close
'Rover.TheConnection.rdoQu
RetCode = Edit(TheAddressID, TheContainer)
If RetCode Then
Add = TheAddressID
Else
Add = 0
End If
Screen.MousePointer = vbDefault
Exit Function
AddressAddError:
Rover.CBPErr.Number = Err.Number
Select Case Rover.CBPErr.Action
Case vbAbort
Add = False
Exit Function
Case vbRetry
Resume
Case Else
Resume Next
End Select
End Function
Try adding the line set rs = new rdo.resultset before the line giving you the error
Sorry add that line before your current set rs line
ASKER
Nope, VB wouldn't allow me to do that.
The line should have read
set rs = new rdoResultset '(no dot)
But why wouldn't VB allow you to do that?
set rs = new rdoResultset '(no dot)
But why wouldn't VB allow you to do that?
ASKER
Invalid use of New Keyword.
From the Vb help file
========================== ========== ========== ========== ========== ========== ====
The following example shows how to create an rdoResultset in code and pass it to an existing RemoteData control:
Option Explicit
Dim qy As rdoQuery
Dim rs As rdoResultset
Dim cn As rdoConnection
Private Sub Form_Load()
Dim SQL As String
Set cn = MSRDC1.Connection
SQL = "{ call ChooseAuthor (?) }"
Set qy = cn.CreateQuery("GetAuthor" , SQL)
End Sub
Private Sub Search_Click()
qy(0) = NameWanted.Text
Set MSRDC1.Resultset = qy.OpenResultset( _
rdOpenStatic, rdConcurReadOnly)
End Sub
Try this syntax and see what happens
==========================
The following example shows how to create an rdoResultset in code and pass it to an existing RemoteData control:
Option Explicit
Dim qy As rdoQuery
Dim rs As rdoResultset
Dim cn As rdoConnection
Private Sub Form_Load()
Dim SQL As String
Set cn = MSRDC1.Connection
SQL = "{ call ChooseAuthor (?) }"
Set qy = cn.CreateQuery("GetAuthor"
End Sub
Private Sub Search_Click()
qy(0) = NameWanted.Text
Set MSRDC1.Resultset = qy.OpenResultset( _
rdOpenStatic, rdConcurReadOnly)
End Sub
Try this syntax and see what happens