MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração


Participe do fórum, é rápido e fácil

MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração

MaximoAccess

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Dicas Ms Access, Exemplos Ms Access, Codigos VBA Ms Access, SQL Ms Access


2 participantes

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Sáb 29 Abr 2017, 12:42 pm

    Olá,

    Estou desenvolvendo um arquivo para um registro especifico do SPED, Sistema Publico de Escrituração Digital. Nele preciso enviar varias linhas com uma série de informações em acordo com layout previamente definido pela Receita Federal do Brasil. Abaixo no tópico 1 consta um exemplo do qual é o formato do arquivo que preciso gerar. Através do código disponibilizado pelo "AhTexeira", moderador neste forum, consegui gerar um arquivo com apenas uma consulta, todavia, preciso enviar as informações para o arquivo .txt de varias consultas. Abaixo consta o código o qual conseguir enviar, código 1, e após o código 2 o qual preciso modificar para gerar a informação que preciso.


    • Tópico 1:


    Código:

    |G001|0|
    |G110|01082016|31082016|9490|197,71|185099,44|185099,44|1|197,71|197,71|
    |G125|MEBENZ|01082016|SI|7280||||39|151,67|
    |G126|01052013|01052013|39|151,67|185099,44|185099,44|1|151,67|
    |G125|CARFUR|01082016|SI|2210||||39|46,04|
    |G126|01052013|01052013|39|46,04|185099,44|185099,44|1|46,04|
    |G990|7|


    • Código 1: Código em funcionamento, mas com a informação Incompleta, apenas uma consulta.


    Código:

    Dim rst As Recordset, varRecCount As Integer, varCount As Integer
    Dim varArq As String
    Dim db As Database

    Set db = CurrentDb()

    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas


    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    varArq = Application.CurrentProject.Path & "\ativoImobilizadoSpedFiscal.txt"
    'Tenta abrir o arquivo em caso de erro GerenErro
    Open varArq For Output As #1

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    rst.MoveNext
    Next varCount
    Close #1
    rst.Close
    Set db = Nothing
    MsgBox "Arquivo TXT foi criado em: " & varArq, vbInformation, "Atenção"
    Exit Sub
    End Sub
    Function LPad_E(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = ""
    If n < 1 Then
    LPad_E = ""
    Else
    LPad_E = Right$(String$(n, Left$(c, 1)) & s, n)
    End If '
    End Function

    Function LPad_D(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = " "
    If n < 1 Then
    LPad_D = "|"
    Else
    LPad_D = Left$(s & String$(n, Left$(c, 1)), n)
    End If
    End Function



    • Código 2: Código com erro, mas com a informação completa, com várias consultas.


    Código:

    Dim rst As Recordset, varRecCount As Integer, varCount As Integer
    Dim varArq As String
    Dim db As Database

    Set db = CurrentDb()

    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG001 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG125 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG126 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG130 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG140 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG990 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    varArq = Application.CurrentProject.Path & "\ativoImobilizadoSpedFiscal.txt"
    'Tenta abrir o arquivo em caso de erro GerenErro
    Open varArq For Output As #1

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount
    Close #1
    rst.Close
    Set db = Nothing
    MsgBox "Arquivo TXT foi criado em: " & varArq, vbInformation, "Atenção"
    Exit Sub
    End Sub
    Function LPad_E(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = ""
    If n < 1 Then
    LPad_E = ""
    Else
    LPad_E = Right$(String$(n, Left$(c, 1)) & s, n)
    End If '
    End Function

    Function LPad_D(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = " "
    If n < 1 Then
    LPad_D = "|"
    Else
    LPad_D = Left$(s & String$(n, Left$(c, 1)), n)
    End If
    End Function


    Grato pela ajuda,
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Sáb 29 Abr 2017, 3:12 pm

    Olá Darlan Sandro

    Parece que abaixo é o ficheiro que pretende criar:

    |G001|0|
    |G110|01082016|31082016|9490|197,71|185099,44|185099,44|1|197,71|197,71|
    |G125|MEBENZ|01082016|SI|7280||||39|151,67|
    |G126|01052013|01052013|39|151,67|185099,44|185099,44|1|151,67|
    |G125|CARFUR|01082016|SI|2210||||39|46,04|
    |G126|01052013|01052013|39|46,04|185099,44|185099,44|1|46,04|
    |G990|7|


    Terá que identificar (relação) dos campos gerados em relação à(s) tabela(s)/Consultas(s).

    Talvez melhor também postar a base de dados com os dados para gerar o ficheiro que postou.
    Abraço
    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Sáb 29 Abr 2017, 7:12 pm

    Olá Teixeira, Obrigado pela ajuda. Abaixo segue link com o banco e vídeo ilustrativo do erro.

    1drv.ms/f/s!AgHCWa12NNUWvXHZKos6NhUnTI6Q
    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Dom 30 Abr 2017, 11:56 am

    Olá Teixeira,

    Tentei estabelecer a relação, contudo não obtive êxito. Abaixo coloco o código. Grato pela ajuda.

    Código:


    Dim rst As Recordset, varRecCount As Integer, varCount As Integer
    Dim varArq As String
    Dim db As Database

    Set db = CurrentDb()
    'Set rst = DB.OpenRecordset("tblNotaFiscalIcmsAntecipacaoParcialSpedFiscal", dbOpenTable) 'se for tabelas
    'Set rst = db.OpenRecordset("SELECT * FROM cstNotaFiscalIcmsVendaInterestadualNaoContribuinteSpedFiscal WHERE filial=" & Me.txtfilial.Value & " and mes=" & Me.txtMes.Value & " and ano=" & Me.txtAno.Value)  'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG001 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG125 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG126 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG130 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG140 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG990 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    varArq = Application.CurrentProject.Path & "\ativoImobilizadoSpedFiscal.txt"
    'Tenta abrir o arquivo em caso de erro GerenErro
    Open varArq For Output As #1
    Open varArq For Output As #2
    Open varArq For Output As #3
    Open varArq For Output As #4
    Open varArq For Output As #5
    Open varArq For Output As #6
    Open varArq For Output As #7

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #2, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #3, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #4, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #5, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #6, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #7, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount
    Close #1
    Close #2
    Close #3
    Close #4
    Close #5
    Close #6
    Close #7
    rst.Close
    Set db = Nothing
    MsgBox "Arquivo TXT foi criado em: " & varArq, vbInformation, "Atenção"
    Exit Sub
    End Sub
    Function LPad_E(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = ""
    If n < 1 Then
    LPad_E = ""
    Else
    LPad_E = Right$(String$(n, Left$(c, 1)) & s, n)
    End If '
    End Function

    Function LPad_D(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = " "
    If n < 1 Then
    LPad_D = "|"
    Else
    LPad_D = Left$(s & String$(n, Left$(c, 1)), n)
    End If
    End Function
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Dom 30 Abr 2017, 12:06 pm

    Olá, baixei o seu projeto, mas dá formato não reconhecido.
    Teste baixar o link que postou se o ficheiro funciona.

    Antes de fazer o upload para partilha, compactar/reparar e crie um ficheiro zip, e só depois é que efetue o upload
    Abraço
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Dom 30 Abr 2017, 2:53 pm

    Olá,
    Na minha mensagem nº 2 queria dizer os campos que vemos de que tabela estão a vir e quais os campos e tabelas que pretende exportar.
    Era essa relação que me referia, exemplo:
    G001 é da tabela X o campo Y...
    E também seria bom explicar em que tabelas e com que filtros e "loops" se for o caso pretende exportar.

    Quanto à minha mensagem anterior verifique.

    Estive a olhar agora um pouco para o código postado na mensagem nº 1 e não compreendo tantos "set recordeset", acho que assim não vai funfar.
    Será que pretende correr todas as filiais????

    Abraço

    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Dom 30 Abr 2017, 7:17 pm

    Olá Teixeira,

    Antes de mais nada obrigado pelo auxílio. Bem, todos os "recordset" referem - se a consultas diferentes. Para cada linha do arquivo em .txt criei uma consulta:

    Código:

    |G001| - >  Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG001 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas

    |G110| - > Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas

    |G125| - > Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG125 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    |G126| - >  Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG126 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    |G130| - >  Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG130 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    |G140| - > Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG140 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    |G990| - > Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG990 WHERE filial=" & Me.txtfilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas


    Trata - se de um única filial. O filtro para todas as consultas acontece quando do fechamento do relatório, como demonstrado no vídeo. Postei o arquivo do banco e vídeo zipado como o solicitado e deixei-os no formato original, concomitantemente testei o link novamente, perdoa-me pelo o erro da postagem anterior, neste momento estão funcionando corretamente. Acrescentei no anexo deste "post".

    Link: onedrive.live.com/?authkey=%21ANkqizo2FSdMjpA&id=16D53476AD59C201%217921&cid=16D53476AD59C201
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Seg 01 maio 2017, 12:42 am

    Olá, continua a dar "base de dados não reconhecida"
    Eu tenho o 2007 e é mdb , estranho!
    Que versão está a usar?
    Se usar superior a 2007, crie novo MDB e importe.

    Se algum colega do fórum poder baixar, testar e dar retorno agradeço
    Abraço
    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Seg 01 maio 2017, 1:05 am

    Olá Teixeira,

    Uso o access 2010, mas não entendi o porque do arquivo não esta executando no access 2007. De qualquer forma, salvei na extensão para o access 2007 através da importação do arquivo em uma nova base. Adicionei os novos arquivos no "Post". Grato pela ajuda mais uma vez.

    Link: 1drv.ms/f/s!AgHCWa12NNUWvXHZKos6NhUnTI6Q
    Anexos
    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel AttachmentnovoGestor.zip
    Você não tem permissão para fazer download dos arquivos anexados.
    (1.2 Mb) Baixado 13 vez(es)
    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Qui 04 maio 2017, 9:09 am

    Olá Darlan Sandro,
    Importando resolveu e sua base de dados não ficou tão grande.

    Hoje arranjei um tempinho, quanto à questão, como já tinha dito tantos recordset seguidos só o ultimo é que está a funcionar.
    E esse último não tem o campo, veja:
    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel 032

    Se pretende efetivamente exportar das varias consultas, deve repetir o procedimento para cada abertura e fecho do recordeset.

    Algo assim:
    Código:
    Private Sub btnGerarTxt_Click()
    Dim rst As Recordset, varRecCount As Integer, varCount As Integer
    Dim varArq As String
    Dim db As Database

    Set db = CurrentDb()
    varArq = Application.CurrentProject.Path & "\ativoImobilizadoSpedFiscal.txt"

    'Tenta abrir o arquivo em caso de erro GerenErro
    Open varArq For Output As #1

    'Set rst = DB.OpenRecordset("tblNotaFiscalIcmsAntecipacaoParcialSpedFiscal", dbOpenTable) 'se for tabelas
    'Set rst = db.OpenRecordset("SELECT * FROM cstNotaFiscalIcmsVendaInterestadualNaoContribuinteSpedFiscal WHERE filial=" & Me.txtfilial.Value & " and mes=" & Me.txtMes.Value & " and ano=" & Me.txtAno.Value)  'se for consultas
    'primeiro recordset
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG001 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount

    'segundo recordeset
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount

    ' terceiro
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG125 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount

    'quarto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG126 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    '...

    'quinto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG130 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    '...

    'sexto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG140 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    '...

    'setimo
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG990 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(rst!DT_DOC) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount
    'fim dos recordset


    Close #1
    rst.Close
    Set db = Nothing
    MsgBox "Arquivo TXT foi criado em: " & varArq, vbInformation, "Atenção"
    Exit Sub
    End Sub

    Abraço
    darlansandro
    darlansandro
    Intermediário
    Intermediário


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Brasil
    Mensagens : 138
    Registrado : 03/05/2014

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  darlansandro Sáb 06 maio 2017, 5:43 pm

    Olá Teixeira,

    Grato amigo, mais uma vez sua ajuda foi essencial e fundamental para solução da demanda. Abaixo estou postando o código pronto, através do qual o problema foi solucionado. Deus o abençoe.

    Código:


    Private Sub btnGerarTxt_Click()
    Dim rst As Recordset, varRecCount As Integer, varCount As Integer
    Dim varArq As String
    Dim db As Database

    Set db = CurrentDb()

    'primeiro recordeset
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG001 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value)  'se for consultas


    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    varArq = Application.CurrentProject.Path & "\ativoImobilizadoSpedFiscal.txt"
    'Tenta abrir o arquivo em caso de erro GerenErro
    Open varArq For Output As #1

    For varCount = 1 To varRecCount
    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_MOV) & "|"

    rst.MoveNext
    Next varCount

    'segundo recordeset
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG110 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIN, "ddmmyyyy")) & "|" & Trim(rst!SALDO_IN_ICMS) & "|" & Trim(rst!SOM_PARC) & "|" & Trim(rst!VL_TRIB_EXP) & "|" & Trim(rst!VL_TOTAL) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!ICMS_APROP, "Fixed")) & "|" & Trim(Format(rst!SOM_ICMS_OC, "Fixed")) & "|"

    rst.MoveNext
    Next varCount

    ' terceiro
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG125 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount


    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!COD_IND_BEM) & "|" & Trim(Format(rst!DT_MOV, "ddmmyyyy")) & "|" & Trim(rst!TIPO_MOV) & "|" & Trim(Format(rst!VL_IMOB_ICMS_OP, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_ST, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_FRT, "Fixed")) & "|" & Trim(Format(rst!VL_IMOB_ICMS_DIF, "Fixed")) & "|" & Trim(Format(rst!NUM_PARC, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|"

    rst.MoveNext
    Next varCount

    'quarto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG126 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount


    Print #1, "|" & Trim(rst!REG) & "|" & Trim(Format(rst!DT_INI, "ddmmyyyy")) & "|" & Trim(Format(rst!DT_FIM, "ddmmyyyy")) & "|" & Trim(rst!NUM_PARC) & "|" & Trim(Format(rst!VL_PARC_PASS, "Fixed")) & "|" & Trim(Format(rst!VL_TRIB_OC, "Fixed")) & "|" & Trim(Format(rst!VL_TOTAL, "Fixed")) & "|" & Trim(Format(rst!IND_PER_SAI, "Fixed")) & "|" & Trim(Format(rst!VL_PARC_APROP, "Fixed")) & "|"

    rst.MoveNext
    Next varCount

    'quinto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG130 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount


    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!IND_EMIT) & "|" & Trim(rst!COD_PART) & "|" & Trim(rst!COD_MOD) & "|" & Trim(rst!SERIE) & "|" & Trim(rst!NUM_DOC) & "|" & Trim(rst!CHV_NFE_CTE) & "|" & Trim(Format(rst!DT_DOC, "ddmmyyyy")) & "|"

    rst.MoveNext
    Next varCount

    'sexto
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG140 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas

    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount

    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!NUM_ITEM) & "|" & Trim(rst!COD_ITEM) & "|"

    rst.MoveNext
    Next varCount

    'setimo
    Set rst = db.OpenRecordset("SELECT * FROM cstAtivoImobilizadoCiapMovimentoMensalSpedFiscalG990 WHERE filial=" & Me.txtFilial.Value & " and numeroMes=" & Me.txtMes.Value & " and numeroAno=" & Me.txtAno.Value) 'se for consultas
    rst.MoveLast
    varRecCount = rst.RecordCount
    rst.MoveFirst

    For varCount = 1 To varRecCount


    Print #1, "|" & Trim(rst!REG) & "|" & Trim(rst!QTD_LIN_G) & "|"

    rst.MoveNext
    Next varCount
    'fim dos recordset


    Close #1
    rst.Close
    Set db = Nothing
    MsgBox "Arquivo TXT foi criado em: " & varArq, vbInformation, "Atenção"
    Exit Sub
    End Sub
    Function LPad_E(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = ""
    If n < 1 Then
    LPad_E = ""
    Else
    LPad_E = Right$(String$(n, Left$(c, 1)) & s, n)
    End If '
    End Function

    Function LPad_D(s, ByVal c As String, n As Integer) As String
    If Len(c) = 0 Then c = " "
    If n < 1 Then
    LPad_D = "|"
    Else
    LPad_D = Left$(s & String$(n, Left$(c, 1)), n)
    End If
    End Function


    Alvaro Teixeira
    Alvaro Teixeira
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 7919
    Registrado : 15/03/2013

    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Alvaro Teixeira Dom 07 maio 2017, 7:09 pm

    Olá Darlan Sandro,
    Obrigado pelo retorno, os utilizadores do fórum agradecem.
    Abraço

    Conteúdo patrocinado


    [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel Empty Re: [Resolvido]Exportar para um arquivo .txt varias consultas na mesma variavel

    Mensagem  Conteúdo patrocinado


      Data/hora atual: Dom 28 Abr 2024, 7:21 pm