Caros colegas, esta instrução Do While deveria inserir 4 registros novos no Rs2. Só que não executa!
Onde está o erro?
Private Sub Comando0_Click()
Dim dbbanco, dbbanco2, dbbanco3 As Database
Dim Rs, Rs2, rssoc As DAO.Recordset
Set dbbanco = CurrentDb()
'Acha os faturados no penúltimo mês.
Set Rs = dbbanco.OpenRecordset("SELECT * FROM [movimentacao] WHERE faturado > 0 and data = DateSerial(Year(Date()), Month(Date())-2,1)")
Set dbbanco2 = CurrentDb()
Set Rs2 = dbbanco2.OpenRecordset("movimentacao", dbOpentable)
Set dbbanco3 = CurrentDb()
Set rssoc = dbbanco3.OpenRecordset("SELECT top 1 * FROM [backupexcel] WHERE bup = 'faturado' order by databup desc")
If rssoc!databup = DateSerial(Year(Date), Month(Date) - 1, 1) Then
Exit Sub
Else
Do While Not Rs.EOF
With Rs2
.AddNew
!CodConta2 = Rs!CodConta2
!Data = DateSerial(Year(Date), Month(Date), 0)
!MesReferencia = DateSerial(Year(Date), Month(Date) - 1, 1)
!Faturado = Rs!Faturado
.Update
Rs2.Close
End With
Rs.MoveNext
Loop
With rssoc
.AddNew
!BUP = "faturado"
!databup = DateSerial(Year(Date), Month(Date) - 1, 1)
!usuariobup = UsuárioAtual()
.Update
rssoc.Close
End With
End If
End Sub
Agradeço desde já!
At
MPS
Onde está o erro?
Private Sub Comando0_Click()
Dim dbbanco, dbbanco2, dbbanco3 As Database
Dim Rs, Rs2, rssoc As DAO.Recordset
Set dbbanco = CurrentDb()
'Acha os faturados no penúltimo mês.
Set Rs = dbbanco.OpenRecordset("SELECT * FROM [movimentacao] WHERE faturado > 0 and data = DateSerial(Year(Date()), Month(Date())-2,1)")
Set dbbanco2 = CurrentDb()
Set Rs2 = dbbanco2.OpenRecordset("movimentacao", dbOpentable)
Set dbbanco3 = CurrentDb()
Set rssoc = dbbanco3.OpenRecordset("SELECT top 1 * FROM [backupexcel] WHERE bup = 'faturado' order by databup desc")
If rssoc!databup = DateSerial(Year(Date), Month(Date) - 1, 1) Then
Exit Sub
Else
Do While Not Rs.EOF
With Rs2
.AddNew
!CodConta2 = Rs!CodConta2
!Data = DateSerial(Year(Date), Month(Date), 0)
!MesReferencia = DateSerial(Year(Date), Month(Date) - 1, 1)
!Faturado = Rs!Faturado
.Update
Rs2.Close
End With
Rs.MoveNext
Loop
With rssoc
.AddNew
!BUP = "faturado"
!databup = DateSerial(Year(Date), Month(Date) - 1, 1)
!usuariobup = UsuárioAtual()
.Update
rssoc.Close
End With
End If
End Sub
Agradeço desde já!
At
MPS