V9 (VBA) - IntraGroup Sales Documents

2

Good afternoon,

After saving a document to an "A" company, you need to create another one in automatic in company "B" and in this to perform the integration in accounting.

I'm having trouble connecting to Accounting. VBA Code:

Sub DocVendaGrupo()

Dim oMotor As New ErpBS
Dim Transacao As New StdBETransaccao
Dim docVenda As New GcpBEDocumentoVenda

‘Abre outra Empresa
oMotor.AbreEmpresaTrabalho tpEmpresarial, “ZGZ”, Aplicacao.Utilizador.Utilizador, Aplicacao.Utilizador.Password, Transacao, Instancia, True

‘Preenche Objeto DocVenda
docVenda.tipodoc = “FA”
docVenda.entidade = “C00588”
docVenda.tipoentidade = “C”
docVenda.CondPag = “1”

oMotor.Comercial.Vendas.PreencheDadosRelacionados docVenda, 5

oMotor.Comercial.Vendas.AdicionaLinha docVenda, “PA205107072.15.00”, 1

oMotor.Comercial.Vendas.Actualiza docVenda

Debug.Print docVenda.tipodoc & ” ” & docVenda.serie & ” ” & docVenda.numdoc & ” ” & oMotor.Contexto.CodEmp

oMotor.Comercial.LigacaoCBL.IntegraDocumentoLogCBL “V”, docVenda.tipodoc, docVenda.serie, docVenda.numdoc, docVenda.Filial

End Sub

In IntegraDocumentoLogCBL, the error occurs: "Object variable or With block variable not set"

The goal is to create the document and perform the integration in accounting in automatic in company "B".

Note: If you go to the VBA of company "B" and put in after saving the:

BSO.Comercial.LigacaoCBL.IntegraDocumentoLogCBL “V”, me.DocumentoVenda.tipodoc, me.DocumentoVenda.serie, me.DocumentoVenda.numdoc, me.DocumentoVenda.Filial

Integration into accounting is accomplished successfully.

Yours sincerely,

Vitor Ferreira

    
asked by anonymous 07.08.2018 / 14:57

1 answer

3

If you are running this code in the from the company A will not be able to integrate the document into Accounting in the company B , or vice versa, because from the moment you execute the following code:

Dim oMotor As New ErpBS
Dim Transacao As New StdBETransaccao

'Abre outra Empresa
oMotor.AbreEmpresaTrabalho tpEmpresarial, "ZGZ", Aplicacao.Utilizador.Utilizador, Aplicacao.Utilizador.Password, Transacao, Instancia, True

You are changing the context of ERP itself, giving rise to errors like this that you put in your question, even if you then try to close the ERP it will stop responding in certain operations.

This type of operations must be carried out within the company (incorporate a company document A into the company A ) or from a specific outside the ERP environment ( or . net ).

The following sequence would be:

  • Declare a new engine (as you did previously: Dim oMotor As New ErpBS )
  • Open the company A and get the document
  • Close the company A
  • Open the company B
  • Create the document in the company B
  • Integrate the document into Company Accounting B
  • Close the company B
  • 07.08.2018 / 15:41