Solved Load a "semi-automatic" combo in a subform

Etxezarreta

Member
Local time
Today, 20:52
Joined
Apr 13, 2020
Messages
175
Hello,
I use the following code to populate a combo in a form called f_GestionPF.
I have been trying to do the same thing to populate a combo called "combo_ProduitSemiFini" in the subform called "sf_CompositionProduitsFinis" of this form,
I know the problem sets in this code line :

Me.combo_FiltreNom.RowSource = sSelect & sWhere & sOrderBy
I tried Me!sf_CompositionProduitsFinis.Form!combo_ProduitSemiFini.rowsource = sSelect & sWhere & sOrderBy, but it doesn't work, would you have any idea please?
Thanks.
Etxe

Code:
Private Sub combo_FiltreNom_KeyPress(KeyAscii As Integer)

On Error GoTo GestionnaireErreur
    If KeyAscii > 32 Then
        sAccumText = sAccumText & Chr(KeyAscii)
    ElseIf KeyAscii = 8 Then 'Backspace Key
        If Len(sAccumText) > 1 Then
            sAccumText = Left(sAccumText, Len(sAccumText) - 1)
        ElseIf Len(sAccumText) = 1 Then
            sAccumText = ""
        End If
        If Nz(Me.combo_FiltreNom.Text, "") = "" Then sAccumText = ""
    End If
    
    Dim sWhere As String
    If sAccumText <> "" Then
        sWhere = "WHERE [CODE_SAGE] LIKE '*" & Replace(sAccumText, "'", "''") & "*' OR [INTITULES_GENERIQUES_PRODUITS_FINIS] LIKE '*" & Replace(sAccumText, "'", "''") & "*' "
    End If
    Me.combo_FiltreNom.RowSource = sSelect & sWhere & sOrderBy
    
    If KeyAscii = 27 Then 'Escape
        sAccumText = ""
    ElseIf KeyAscii = 8 And sAccumText = "" Then
        'Backspace key, do nothing
    ElseIf KeyAscii = 9 Then 'Tab
        sAccumText = ""
    Else
        Me.combo_FiltreNom.Dropdown
    End If
    'This textbox not required, only here to show you what you've been typing
    Me.txtAccumText = sAccumText
    
    Exit Sub
GestionnaireErreur:
    MsgBox "Une erreur s'est produite: " & Err.Number & "-" & Err.Description, vbOKOnly + vbInformation
 
Hi. If the combo is on the main form, the syntax is something like this:

Code:
Me.ComboName.RowSource = sSelect...

But if the combo is on a subform, and your code is still on the main form, then that syntax changes to something like this:

Code:
Me.SubformControlName.Form!ComboName.RowSource = sSelect...

The main thing to remember there is, you need to use the name of the subform control - not the name of the form in the subform.

Hope that helps...
 
Hi The DBguy,
Yes, the trick was indeed to use the original subform name, it works.
Thank you then, and have a good day.
Etxe.
 
Hi The DBguy,
Yes, the trick was indeed to use the original subform name, it works.
Thank you then, and have a good day.
Etxe.
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom