Results 1 to 9 of 9

Thread: vb6 INNER JOIN ADODB.recordset

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    5

    Exclamation vb6 INNER JOIN ADODB.recordset

    Hello,

    I'm trying to join 2 combobox with Microsoft Access database. With this code it give me this error message at line 36: Error number 3705 Description: This operation is not authorised if the object is open.
    Code:
    Public Sub RemplirComboFabricant()
    
    5       On Error GoTo AfficherErreur
    
            'Rempli le combo des fabricants
    10      Dim rstFabricant As ADODB.Recordset
    15      Dim sCategorie   As String
    20      Dim iCompteur    As Integer
    21      Dim sFabricant   As String
      
    25      sCategorie = Replace(cmbCategorie.Text, "'", "''")
      
    30      Set rstFabricant = New ADODB.Recordset
    
    35      Call rstFabricant.Open("SELECT DISTINCT FABRICANT FROM GRB_CatalogueElec WHERE CATEGORIE = '" & sCategorie & "' ORDER BY FABRICANT", g_connData, adOpenDynamic, adLockOptimistic)
    36      Call rstFabricant.Open("SELECT * FROM GRB_CatalogueElec INNER JOIN GRB_InventaireElec ON GRB_CatalogueElec.FABRICANT=GRB_InventaireElec.Localisation WHERE GRB_CatalogueElec.FABRICANT LIKE '" & sFabricant & "'  ORDER BY FABRICANT", g_connData, adOpenDynamic, adLockOptimistic)
    
            'Il faut vider le combo avant de le remplir
    40      Call cmbFabricant.Clear
    41      sChoisirTous = ""
          'on ajoute la possibilité de choisir tout les fabricants
    42      Call cmbFabricant.AddItem("-- CHOISIR TOUS --")
    43        If Not rstFabricant.EOF Then
    44          rstFabricant.MoveFirst
              End If
            'Tant que ce n'est pas la fin des enregistrements
            
    45      Do While Not rstFabricant.EOF
              'Si l'élément n'est pas null
              
    50        If Not IsNull(rstFabricant.Fields("Fabricant")) Then
                
                'on l'ajoute
    55          Call cmbFabricant.AddItem(Trim(rstFabricant.Fields("FABRICANT")))
                If sChoisirTous = "" Then
                    sChoisirTous = " AND (FABRICANT = '" & Trim(rstFabricant.Fields("FABRICANT")) & "'"
                Else
    56              sChoisirTous = sChoisirTous + " OR FABRICANT = '" & Trim(rstFabricant.Fields("FABRICANT")) & "'"
                End If
    60        End If
        
    65        Call rstFabricant.MoveNext
                
    70      Loop
            
            sChoisirTous = sChoisirTous + ")"
            
    75      Call rstFabricant.Close
    80      Set rstFabricant = Nothing
            
            'Si le combo n'est pas vide, on sélectionne le premier élément
    85      If cmbFabricant.ListCount > 0 Then
                
    90        If m_sSelectFabricant <> vbNullString Then
    95          For iCompteur = 0 To cmbFabricant.ListCount - 1
                    
    100           If UCase(cmbFabricant.LIST(iCompteur)) = UCase(m_sSelectFabricant) Then
    105             cmbFabricant.ListIndex = iCompteur
                    
    110             m_sSelectFabricant = ""
                    
    115             Exit For
    120           End If
    125         Next
                
    130       Else
                
    135         cmbFabricant.ListIndex = 0
                
    140       End If
    145     Else
                
    150       Call cmbNoItem.Clear
    155       Call cmbDescriptionFR.Clear
    160     End If
            
    165     Exit Sub
    
    AfficherErreur:
    
    170     Call AfficherErreur("frmCatalogueElec", "RemplirComboFabricant", Err, Erl)
    End Sub
    The databases from Access are;

    GRB_CatalogueElec:Name:  Microsoft Access - [GRB_CatalogueElec _ Table].jpg
Views: 531
Size:  15.4 KB



    GRB_InventaireElec:Name:  Microsoft Access - [GRB_InventaireElec _ Table].jpg
Views: 591
Size:  21.4 KB

    Is my syntaxe correct or it's something else? I don't know. What I want it to do is when you select a localisation it will automaticaly select fill in the possible maker(fabricant)/manufacturer(manufacturier) linked with that localisation from the Access database.

    Thanks!
    Last edited by XavierCG; Dec 14th, 2022 at 01:56 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: vb6 INNER JOIN ADODB.recordset

    Code:
    35      Call rstFabricant.Open("SELECT DISTINCT FABRICANT FROM GRB_CatalogueElec WHERE CATEGORIE = '" & sCategorie & "' ORDER BY FABRICANT", g_connData, adOpenDynamic, adLockOptimistic)
    36      Call rstFabricant.Open("SELECT * FROM GRB_CatalogueElec INNER JOIN GRB_InventaireElec ON GRB_CatalogueElec.FABRICANT=GRB_InventaireElec.Localisation WHERE GRB_CatalogueElec.FABRICANT LIKE '" & sFabricant & "'  ORDER BY FABRICANT", g_connData, adOpenDynamic, adLockOptimistic)
    Line 35 opens the recordset ... and then you open it AGAIN in the next line. That doesn't work. If you open a door... can you open it again immediately? No... what do you have to do before you can open it a second time? Close it. Same with the recordsets .. either close it, in which case why was it open in the first place? Or use a different recordset for the second operation.


    -tg
    Last edited by techgnome; Dec 14th, 2022 at 11:58 AM. Reason: fixed code tag
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    5

    Re: vb6 INNER JOIN ADODB.recordset

    I used a different recordset to try it out.
    I added :
    Code:
    11            Dim rstLocalisation as ADODB.Recordset
    36            Call rstLocalisation.Open("SELECT * FROM GRB_CatalogueElec INNER JOIN GRB_InventaireElec ON GRB_CatalogueElec.FABRICANT=GRB_InventaireElec.Localisation WHERE GRB_CatalogueElec.FABRICANT LIKE '" & sFabricant & "'  ORDER BY FABRICANT", g_connData, adOpenDynamic, adLockOptimistic)
    It still doesn't work.
    Error number 91 Description: Variable object or variable bloc With not defined

    And I can't see the manufacturer in the combobox.

    Thanks

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: vb6 INNER JOIN ADODB.recordset

    Did you create a new instance? I don't mean the dim line ... I mean a line like this:
    Code:
    Set rstFabricant = New ADODB.Recordset
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    5

    Re: vb6 INNER JOIN ADODB.recordset

    Quote Originally Posted by techgnome View Post
    Did you create a new instance? I don't mean the dim line ... I mean a line like this:
    Code:
    Set rstFabricant = New ADODB.Recordset
    -tg
    Now theres no more errors but the localisation doesn't stay once you click one and the manufacturer combobox doesn't change when selecting a localisation. I'm not sure why it is not working like expected and for the other comboxbox it work just fine.

    Thanks.

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: vb6 INNER JOIN ADODB.recordset

    Quote Originally Posted by XavierCG;[URL="tel:5588931"
    5588931[/URL]]Now theres no more errors but the localisation doesn't stay once you click one and the manufacturer combobox doesn't change when selecting a localisation. I'm not sure why it is not working like expected and for the other comboxbox it work just fine.

    Thanks.
    besides the fact that sFabricant is nowhere set before you open that recordset?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    5

    Re: vb6 INNER JOIN ADODB.recordset

    Quote Originally Posted by Zvoni View Post
    besides the fact that sFabricant is nowhere set before you open that recordset?
    You mean like line 25 but for sFabricant?

    I have put one there like this:
    Code:
    sFabricant = Replace(cmbFabricant.Text, "'", "''")
    But it doesn't change anything.

    Thanks.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: vb6 INNER JOIN ADODB.recordset

    Quote Originally Posted by XavierCG;[URL="tel:5588939"
    5588939[/URL]]You mean like line 25 but for sFabricant?

    I have put one there like this:
    Code:
    sFabricant = Replace(cmbFabricant.Text, "'", "''")
    But it doesn't change anything.

    Thanks.
    because the LIKE-Operator without wildcards acts like equality?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2022
    Posts
    5

    Re: vb6 INNER JOIN ADODB.recordset

    Yes that's what I'm thinking. That is what is told here I guess?
    Last edited by XavierCG; Dec 14th, 2022 at 02:07 PM. Reason: adding confirmation of what said in post #8

Tags for this Thread

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