Hi all,
First of all, thanks and I am still learning VBA...
I am having some problems with this UPDATE query, access give me errors with <CurrentDb.Execute "UPDATE CAMPOS SET HODDIF = TempB>
I have done it to update my DataBase after a certain field is included.
The code is below. Thanks in advance.
Dim rsta As Recordset
Dim rstb As Recordset
Dim TempA As Integer
Dim TempB As Integer
Set rsta = CurrentDb.OpenRecordset("SELECT * FROM FROTA5 ORDER BY PLACA ASC"
rsta.FindFirst ("PLACA > ''"
Checha_Validade_Placa:
If rsta.NoMatch = True Then
GoTo As_Placas_Acabaram
Else
TempA = 0
Set rstb = CurrentDb.OpenRecordset("SELECT * FROM CAMPOS WHERE PLACA = '" & rsta!PLACA & "' ORDER BY HODFINAL ASC"
rstb.FindFirst ("HODFINAL > 0"
Checa_Validade_Registro:
If rstb.NoMatch = True Then
rsta.FindNext ("PLACA > ''" 'get next record string
GoTo Checha_Validade_Placa
Else
If TempA = 0 Then
TempA = rstb!HODFINAL
Pega_Proximo_Registro:
rstb.FindNext ("HODFINAL > 0" 'get next record
GoTo Checa_Validade_Registro
Else
TempB = rstb!HODINICIAL - TempA
CurrentDb.Execute "UPDATE CAMPOS SET HODDIF = TempB"
TempA = rstb!HODFINAL
GoTo Pega_Proximo_Registro
End If
End If
End If
Placa_Sem_Mais_Registros:
As_Placas_Acabaram:
MsgBox ("as placas acabaram" 'this just show me the execution is finished
Exit Sub
First of all, thanks and I am still learning VBA...
I am having some problems with this UPDATE query, access give me errors with <CurrentDb.Execute "UPDATE CAMPOS SET HODDIF = TempB>
I have done it to update my DataBase after a certain field is included.
The code is below. Thanks in advance.
Dim rsta As Recordset
Dim rstb As Recordset
Dim TempA As Integer
Dim TempB As Integer
Set rsta = CurrentDb.OpenRecordset("SELECT * FROM FROTA5 ORDER BY PLACA ASC"
rsta.FindFirst ("PLACA > ''"
Checha_Validade_Placa:
If rsta.NoMatch = True Then
GoTo As_Placas_Acabaram
Else
TempA = 0
Set rstb = CurrentDb.OpenRecordset("SELECT * FROM CAMPOS WHERE PLACA = '" & rsta!PLACA & "' ORDER BY HODFINAL ASC"
rstb.FindFirst ("HODFINAL > 0"
Checa_Validade_Registro:
If rstb.NoMatch = True Then
rsta.FindNext ("PLACA > ''" 'get next record string
GoTo Checha_Validade_Placa
Else
If TempA = 0 Then
TempA = rstb!HODFINAL
Pega_Proximo_Registro:
rstb.FindNext ("HODFINAL > 0" 'get next record
GoTo Checa_Validade_Registro
Else
TempB = rstb!HODINICIAL - TempA
CurrentDb.Execute "UPDATE CAMPOS SET HODDIF = TempB"
TempA = rstb!HODFINAL
GoTo Pega_Proximo_Registro
End If
End If
End If
Placa_Sem_Mais_Registros:
As_Placas_Acabaram:
MsgBox ("as placas acabaram" 'this just show me the execution is finished
Exit Sub