How to set Form Command and Refresh?

I have a form with a subform and a table control within. The main form have controls to get input from the user. When the button on the main form is clicked I change the Command property of the subform, but I’m not getting to update or refresh or reload the subform to show the result of the new query.

This is the Macro that I’be attached to the button:

Sub FiltrarProdutosTransferidos
	Dim oForm: oForm = Forms("Total de Produtos Transferidos").Controls("FrmProdutos").Form
	oForm.DatabaseForm.Command = "SELECT 'Teste' AS ""Produto"", 69420 AS ""Total"" FROM ""Produtos"""
    ' Doesn't do anything...
	oForm.DatabaseForm.Reload()
End Sub

P.S: I’m using the Access2Base library.

The code seems correct.
What is strange is the SELECTion of 2 constants (‘Teste’ and 69420) only.

2 suggestions:

  • Try to insert the command manually to see what happens
  • attach a sample of your database on this site, to allow readers to support you more efficiently
1 Like

I’ve managed to achieve what I was looking for. Looking in the Access2Base API I found the RecordSource property of the Form object that when updated triggers a requery and refresh of the form.
My final code is the following:

Sub FiltrarProdutosTransferidos
	Dim oForm: oForm = Forms("Totais de Produtos Transferidos")
	Dim oSubForm: oSubForm = oForm.Controls("FrmProdutos").Form
	Dim LbxDe: LbxDe = oForm.Controls("LbxDe")
	' Rest of the controls...
	Dim sSql: sSql = "..."
	' Building query with controls' values...
    ' Updating the form's content
	oSubForm.RecordSource = sSql
End Sub

And the final result:

Screenshot_20231109_084251

Thanks to @JPLED for help.