Results 1 to 26 of 26

Thread: [RESOLVED] Object variable or with block variable not set

  1. #1

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Resolved [RESOLVED] Object variable or with block variable not set

    Hi Everybody !

    I got this error(Title) and I dont know where to begin the "Debug operation" ???

    Here is my code (Sorry some words are in french), the error occurs at the Bolded/Underlined line
    VB Code:
    1. 'Initialisation de la Connection et du Recordset
    2.         'Instanciation des variables
    3.         Set rs = New ADODB.Recordset
    4.         Set cn = New ADODB.Connection
    5.         'Connection et ouverture de la Database
    6.         cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & lblProjetSource.Caption
    7.        
    8. 'Afficher les données (Onglet Informations)
    9.         'Ouverture de la Connection
    10.         cn.Open
    11.         'Ouverture du Recordset
    12.         rs.Open "Informations", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    13.         rs.MoveFirst
    14.                 frMain.txtNoProjet.Text = rs.Fields("NoProjet").Value
    15.                 frMain.cboInfoRepresentant.Text = rs.Fields("Representant").Value
    16.                 frMain.cboInfoTypeClient.Text = rs.Fields("TypeClient").Value
    17.                 frMain.txtNom(0).Text = rs.Fields("NAcheteur1").Value
    18.                 frMain.txtPrenom(0).Text = rs.Fields("PAcheteur1").Value
    19.                 frMain.txtNom(1).Text = rs.Fields("NAcheteur2").Value
    20.                 frMain.txtPrenom(1).Text = rs.Fields("PAcheteur2").Value
    21.                 frMain.txtCompagnie.Text = rs.Fields("Compagnie").Value
    22.                 frMain.txtContactP.Text = rs.Fields("PContact").Value
    23.                 frMain.txtContactN.Text = rs.Fields("NContact").Value
    24.                 frMain.txtAdresse(0).Text = rs.Fields("AddActuelle").Value
    25.                 frMain.txtVille(0).Text = rs.Fields("VilleActuelle").Value
    26.                 frMain.txtCodePostal(0).Text = rs.Fields("CPostalActuel").Value
    27.                 frMain.txtAdresse(1).Text = rs.Fields("AddFutur").Value
    28.                 frMain.txtVille(1).Text = rs.Fields("VilleFutur").Value
    29.                 frMain.txtCodePostal(1).Text = rs.Fields("CPostalFutur").Value
    30.                 frMain.txtTelephone(0).Text = rs.Fields("TelephoneR").Value
    31.                 frMain.txtTelephone(1).Text = rs.Fields("TelephoneC").Value
    32.                 frMain.txtTelephone(2).Text = rs.Fields("TelephoneB").Value
    33.                 frMain.txtTelephone(3).Text = rs.Fields("Telecopieur").Value
    34.                 frMain.txtCourriel.Text = rs.Fields("Courriel").Value
    35.                 frMain.lblDatedujour.Caption = rs.Fields("Date").Value
    36.         'Fermeture de la connection ADO
    37.         rs.Close
    38.         cn.Close
    39.  
    40. 'Afficher les données Cotation
    41.         'Ouverture de la Connection
    42.         cn.Open
    43.         'Ouverture du Recordset
    44.         rs.Open "Cotation", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    45.         rs.MoveFirst
    46.                 frMain.txtVente.Text = rs.Fields("Vente").Value
    47.                 frMain.txtEntente.Text = rs.Fields("Entente").Value
    48.                 frMain.txtEchange.Text = rs.Fields("Echange").Value
    49.                 frMain.txtAccompte.Text = rs.Fields("Accompte").Value
    50.                 frMain.txtTaxe1 = rs.Fields("Taxe1").Value
    51.                 frMain.txtTaxe2 = rs.Fields("Taxe2").Value
    52.                 varCreditTaxe = rs.Fields("TaxeRed").Value
    53.                 If rs.Fields("TaxesReduitesApp").Value = "True" Then
    54.                         frMain.chkTaxesRed.Value = vbChecked
    55.                 Else
    56.                         frMain.chkTaxesRed.Value = vbUnchecked
    57.                 End If
    58.         'Fermeture de la connection ADO
    59.         rs.Close
    60.         cn.Close
    61.  
    62. 'Afficher les données Maison
    63.         'Ouverture de la Connection
    64.         cn.Open
    65.         'Ouverture du Recordset
    66.         rs.Open "Maison", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    67.         rs.MoveFirst
    68.                 frMain.cboMaisonType.Text = rs.Fields("TypeMaison").Value
    69.                 [U][B]frMain.cboMaisonModele.Text = rs.Fields("ModeleMaison").Value[/B][/U]
    70.                 frMain.cboMaisonNbChambre.Text = rs.Fields("NbreChambre").Value
    71.                 frMain.txtDim(0).Text = rs.Fields("DimMaison1").Value
    72.                 frMain.txtDim(1).Text = rs.Fields("DimMaison2").Value
    73.                 frMain.txtDim(2).Text = rs.Fields("DimAnnexeA1").Value
    74.                 frMain.txtDim(3).Text = rs.Fields("DimAnnexeA2").Value
    75.                 frMain.txtDim(4).Text = rs.Fields("DimAnnexeB1").Value
    76.                 frMain.txtDim(5).Text = rs.Fields("DimAnnexeB2").Value
    77.                 frMain.txtDim(6).Text = rs.Fields("DimGarage1").Value
    78.                 frMain.txtDim(7).Text = rs.Fields("DimGarage2").Value
    79.                 frMain.txtSuperficie.Text = rs.Fields("Superficie").Value
    80.                 frMain.cboMaisonGarantie.Text = rs.Fields("Garantie").Value
    81.         'Fermeture de la connection ADO
    82.         rs.Close
    83.         cn.Close
    Thanks in advance !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    First off, I would open the adReadOnly. You don't seem to be changing the values.

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Object variable or with block variable not set

    if the table name is correct and the combo box exists and is named correctly then the field value is probably null... concatenate a zero length string to convert nulls before assigning to text property

    frMain.cboMaisonModele.Text = rs.Fields("ModeleMaison").Value & ""

  4. #4

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    First off, I would open the adReadOnly. You don't seem to be changing the values.
    What I have to replace with adReadOnly ?
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  5. #5
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    Example

    rs.Open "Informations", cn, adOpenKeyset, adReadOnly, adCmdTable

  6. #6

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by leinad31
    if the table name is correct and the combo box exists and is named correctly then the field value is probably null... concatenate a zero length string to convert nulls before assigning to text property

    frMain.cboMaisonModele.Text = rs.Fields("ModeleMaison").Value & ""
    I tried this, and it's not okay...

    I tried also to put a value frMain.cboMaisonModele.Text = "Whatever" and the error still occurs but on the next line...
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  7. #7
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    I would also set thinsg = nothing when not needed.

    rs.close
    set rs = nothing


    then

    Set rs = New ADODB.Recordset
    rs.Open "Informations", cn, adOpenKeyset, adReadOnly, adCmdTable

    etc
    etc

  8. #8

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    Example

    rs.Open "Informations", cn, adOpenKeyset, adReadOnly, adCmdTable
    Now I got an error on this line...
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  9. #9
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    adLockReadOnly... my bad

  10. #10

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    adLockReadOnly... my bad
    I change with this and the error still occurs...
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  11. #11
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Object variable or with block variable not set

    Are you sure the table has records? You never did any tests... you assumed at least one record exists for all rs.Open

  12. #12

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by leinad31
    Are you sure the table has records? You never did any tests... you assumed at least one record exists for all rs.Open
    Yeah Im really sure !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  13. #13
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    Try, after the rs.close,

    set rs = nothing

    then set rs = new adodb.recordset
    before doing next db access.

    The readonly thing would not affect your initial error, it would just cause less impact on the db.

  14. #14

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    Try, after the rs.close,

    set rs = nothing

    then set rs = new adodb.recordset
    before doing next db access.

    The readonly thing would not affect your initial error, it would just cause less impact on the db.
    About this, I did it but it's not on the part of the code I posted...
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Object variable or with block variable not set

    Is this a public recordset?

    Any chance your setting it to nothing elsewhere in your project such as in the change event of the combo's?

    You could try using a recordset with procedure lvl scope

  16. #16
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    If you have "hidden" some off the code, you must post it. We are only able to go on what you post. In it, you set rs = new adodb.recordset at the start of the code, not each time you needed it. Maybe, you are carrying some 'memory-residual' bits. By setting it to nothing when you close it, it should be cleared from memory. However, that implies that you will need a "set rs = new adodb.recordset" the next time you wish to open rs.

  17. #17

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by leinad31
    Is this a public recordset?

    Any chance your setting it to nothing elsewhere in your project such as in the change event of the combo's?

    You could try using a recordset with procedure lvl scope
    I think you're right with your suggestion...

    When I got the error 91, is it possible to know at this moment if rs = nothing ?
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  18. #18

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    If you have "hidden" some off the code, you must post it. We are only able to go on what you post. In it, you set rs = new adodb.recordset at the start of the code, not each time you needed it. Maybe, you are carrying some 'memory-residual' bits. By setting it to nothing when you close it, it should be cleared from memory. However, that implies that you will need a "set rs = new adodb.recordset" the next time you wish to open rs.
    Here is the missing part of code, sorry !
    VB Code:
    1. 'Vider les paramètres
    2.         Set rs = Nothing
    3.         Set cn = Nothing
    4.        
    5.         'Fermeture de la Form
    6.         Unload Me
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  19. #19
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    I think if rs were set to nothing, you would get the error on this line

    rs.Open "Maison", cn, adOpenKeyset, adLockPessimistic, adCmdTable

  20. #20

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    I think if rs were set to nothing, you would get the error on this line

    rs.Open "Maison", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    Is it possible to know moment when the error occurs, if rs is set to nothing ???
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  21. #21
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    Why do you keep opening & closing the connection? Seems like a lot of overhead..

    This is spelled correctly? " cboMaisonModele "

  22. #22

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    Why do you keep opening & closing the connection? Seems like a lot of overhead..
    Because I change the Table, it's not okay ?

    Quote Originally Posted by Pasvorto
    This is spelled correctly? " cboMaisonModele "
    Yeah !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  23. #23
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    Your 'connection' opens the database. Your 'recordset open' code opens the table. You do not need to keep reconnecting to the db. Try commenting the unecessary connections out and see what happens.

  24. #24

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    Quote Originally Posted by Pasvorto
    Your 'connection' opens the database. Your 'recordset open' code opens the table. You do not need to keep reconnecting to the db. Try commenting the unecessary connections out and see what happens.
    Cool !

    I removed the others cn.open and cn.close, Thanks I appreciate !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  25. #25

    Thread Starter
    Hyperactive Member DubweiserTM's Avatar
    Join Date
    Dec 2005
    Location
    St-Ferdinand, Québec
    Posts
    427

    Re: Object variable or with block variable not set

    I replaced rs by rs1 and cn by cn1 and now its' okay !

    Maybe somewhere in my code the rs and cn are set to nothing...

    Thanks for all guys !
    DubweiserTM

    If your question has been answered, you can mark a thread as resolved...

  26. #26
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Object variable or with block variable not set

    Be sure to mark the thread as resolved

Posting Permissions

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



Click Here to Expand Forum to Full Width