Requery a subform from another form?

前端 未结 7 1085
迷失自我
迷失自我 2021-02-02 18:02

I\'ve struggling with this problem on my own, then with some help, then search about it; but I haven\'t had any luck. So I decided to ask.

I have two forms in Access

7条回答
  •  南方客
    南方客 (楼主)
    2021-02-02 19:03

    I had a similar kind of issue, but with some differences...

    In my case, my main form has a Control (vendor) which value I used to update a Query in my DB, using the following code:

    Sub Set_Qry_PedidosRealizadosImportados_frm(Vd As Long)
    Dim temp_qry As DAO.QueryDef
    
    'Procedimento para ajustar o codigo do cliente na Qry_Pedidos realizados e importados
    'Procedure to adjust the code of the client on Qry_Pedidos realizados e importados
    Set temp_qry = CurrentDb.QueryDefs("Qry_Pedidos realizados e importados")
    temp_qry.SQL = "SELECT DISTINCT " & _
                "[Qry_Pedidos distintos].[Codigo], " & _
                "[Qry_Pedidos distintos].[Razao social], " & _
                "COUNT([Qry_Pedidos distintos].[Pedido Avante]) As [Pedidos realizados], " & _
                "SUM(IIf(NZ([Qry_Pedidos distintos].[Pedido Flexx], 0) > 1, 1, 0)) As [Pedidos Importados] " & _
                "FROM [Qry_Pedidos distintos] " & _
                "WHERE [Qry_Pedidos distintos].Vd = " & Vd & _
                " Group BY " & _
                "[Qry_Pedidos distintos].[Razao social], " & _
                "[Qry_Pedidos distintos].[Codigo];"
    End Sub
    

    Since the beginning my subform record source was the query named "Qry_Pedidos realizados e importados".

    But the only way I could update the subform data inside the main form context was to refresh the data source of the subform to it self, like posted bellow:

    Private Sub cmb_vendedor_v1_Exit(Cancel As Integer)
    'Codigo para atualizar o comando SQL da query
    'Code to update the SQL statement of the query 
        Call Set_Qry_Pedidosrealizadosimportados_frm(Me.cmb_vendedor_v1.Value)
    
    'Codigo para forçar o Access a aceitar o novo comando SQL
    'Code to force de Access to accept the new sql statement
        Me!Frm_Pedidos_realizados_importados.Form.RecordSource = "Qry_Pedidos realizados e importados"
    End Sub
    

    No refresh, recalc, requery, etc, was necessary after all...

提交回复
热议问题