dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: object variable or with block variable not set error

  1. #1
    Join Date
    May 2005
    Posts
    178

    object variable or with block variable not set error

    im trying to put some information from xml to a recordset but im getting the error -> "object variable or with block variable not set "
    here is the code-

    Dim rs As New ADODB.Recordset
    rs.ActiveConnection = Nothing
    rs.CursorLocation = adUseClient
    rs.LockType = adLockBatchOptimistic
    rs.fields.Append "client", adInteger, 100

    Dim i As Integer
    rs.Open
    For i = 0 To x.documentElement.childNodes.length
    rs.AddNew
    rs.fields("client") = x.documentElement.childNodes(i).childNodes(0).Text
    Next

    i guess the problem is with the recordset but what is it?
    how can i correct it?
    thanks in advanced

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,267

    Re: object variable or with block variable not set error

    Quote Originally Posted by ppl1
    im trying to put some information from xml to a recordset but im getting the error -> "object variable or with block variable not set "
    here is the code-

    Dim rs As New ADODB.Recordset
    rs.ActiveConnection = Nothing
    rs.CursorLocation = adUseClient
    rs.LockType = adLockBatchOptimistic
    rs.fields.Append "client", adInteger, 100

    Dim i As Integer
    rs.Open
    For i = 0 To x.documentElement.childNodes.length
    rs.AddNew
    rs.fields("client") = x.documentElement.childNodes(i).childNodes(0).Text
    Next

    i guess the problem is with the recordset but what is it?
    how can i correct it?
    thanks in advanced
    I take it that the error is with rs
    Use Set
    Example:
    Code:
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  3. #3
    Join Date
    May 2005
    Posts
    178

    Re: object variable or with block variable not set error

    i already tried that but it didnt help
    can else can it be?

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,267

    Re: object variable or with block variable not set error

    On which line does it give you the error
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  5. #5
    Join Date
    May 2005
    Posts
    178

    Re: object variable or with block variable not set error

    on the line after rs.AddNew

    a also tried rs.fields("client").Value=....
    but it didnt help

  6. #6
    Join Date
    May 2005
    Posts
    178

    Re: object variable or with block variable not set error

    ohh stupit me...
    i forgot to dec 1 from the for-
    For i = 0 To x.documentElement.childNodes.length - 1
    thanks

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,267

    Re: object variable or with block variable not set error

    Cool!
    Happy you sorted it out!
    9 out of 10 times it is something silly
    Last edited by HanneSThEGreaT; September 27th, 2005 at 07:03 AM.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  8. #8
    Join Date
    May 2005
    Posts
    178

    Re: object variable or with block variable not set error

    Dim x As New MSXML.DOMDocument
    x.async = False
    x.loadXML (obj.functionName())

    obj -> class library

  9. #9
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: object variable or with block variable not set error

    Sorry for intruding. But i just want to add few things that I feel are important when coding in VB 6.0

    I have observed in the above code that the New keyword is used in the same line where the Object is declared. This is not a good practice.

    When you use New Keyword in the DIM Statement, VB both creates a variable named and sets up internal code that will instantiate the object referred to by the variable when necessary. The problem with this technique is that it's not clear when your object gets initialized, especially if the object is public and might be referenced from within any module.

    So it is always better to do like this
    Code:
    Dim rs as ADODB.RecordSet
    'This statement will be written only before the Object is used in the code
    Set rs = New ADODB.Recordset

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,267

    Re: object variable or with block variable not set error

    Don't worry, your'e not intruding!
    I've also recommended it - it just makes better sense!
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  11. #11
    Join Date
    May 2005
    Posts
    178

    Re: object variable or with block variable not set error

    ok...thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)