I am facing a challenge with my VBA project.
I recently created a form where the ListBox component and CommandButton, nothing complex. But does the form always disappear from the VBA, any idea what it should be?
Form Code:
Private Sub CommandButtonGuardar_Click()
On Error GoTo TrataErro
EditorVendas.DocumentoVenda.CamposUtil("CDU_Banco") = ListBox1.List(ListBox1.ListIndex, 1)
Unload Me
Exit_point:
On Error Resume Next
Exit Sub
TrataErro:
PSO.Dialogos.MostraAviso "Ocorreu um erro ao selecionar o banco: " & Err.Description, PRI_Critico
Resume Exit_point
End Sub
Private Sub UserForm_Activate()
On Error GoTo TrataErro
Dim ListaSql As StdBELista
'Buscar os Bancos
Set ListaSql = BSO.Consulta("Select Conta,Banco,DescBanco,NumConta from contasbancarias where Banco <> ''")
If Not (ListaSql Is Nothing) Then
'Percorrer a lista
If ListaSql.NumLinhas <> 0 Then
While Not (ListaSql.NoInicio Or ListaSql.NoFim)
'Adciona item a lista
With ListBox1
.ColumnCount = 4
.AddItem
.List(i, 0) = ListaSql("Banco")
.List(i, 1) = ListaSql("Conta")
.List(i, 2) = ListaSql("DescBanco")
.List(i, 3) = Format(ListaSql("NumConta"), "#### #### #####")
End With
i = i + 1
ListaSql.Seguinte
Wend
End If
End If
Exit_point:
On Error Resume Next
Set ListaSql = Nothing
Exit Sub
TrataErro:
PSO.Dialogos.MostraAviso "Ocorreu um erro ao inicializar o formulario.: " & Err.Description, PRI_Critico
Resume Exit_point
End Sub
Here, in the EditorDialog , this is where I call the form:
Private Sub EditorVendas_AntesDeImprimir(Cancel As Boolean)
On Error GoTo TrataErro
'######## Pedir Conta Bancaria imprimir no report de Venda (FA ou outros que venham a existir ######
'######## Author: Cabral Ussene
'######## Date: 2018/05/09
'######## Review Date: 2018/05/11 by Cabral Ussene
If BSO.Comercial.TabVendas.DaValorAtributo(Me.DocumentoVenda.TipoDoc, "CDU_MostrarCBancaria") Then frmContaBancaria.Show
'Validar se foi actualizado a conta bancaria
If Antiga_ContaBancaria <> DocumentoVenda.CamposUtil("CDU_Banco") Then
'Actualizar a CDU_Banco
BSO.Comercial.Vendas.ActualizaValorAtributo DocumentoVenda.Filial, DocumentoVenda.TipoDoc, DocumentoVenda.Serie, DocumentoVenda.NumDoc, "CDU_Banco", DocumentoVenda.CamposUtil("CDU_Banco")
End If
'####################################################################################################
Exit_point:
On Error Resume Next
Exit Sub
TrataErro:
PSO.Dialogos.MostraAviso "Ocorreu um erro antes de imprimir o documento...", PRI_Critico, Err.Description
Resume Exit_point
End Sub
However, what happens is when the user is going to print the document, this is an error, and when they check in the VBA project the form frmContaBancaria is not there, as if someone had deleted it .