Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with UPDATE query

Status
Not open for further replies.

Weendigo

Technical User
Jul 3, 2002
6
BR
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 &quot;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(&quot;SELECT * FROM FROTA5 ORDER BY PLACA ASC&quot;)
rsta.FindFirst (&quot;PLACA > ''&quot;)

Checha_Validade_Placa:

If rsta.NoMatch = True Then
GoTo As_Placas_Acabaram
Else
TempA = 0
Set rstb = CurrentDb.OpenRecordset(&quot;SELECT * FROM CAMPOS WHERE PLACA = '&quot; & rsta!PLACA & &quot;' ORDER BY HODFINAL ASC&quot;)
rstb.FindFirst (&quot;HODFINAL > 0&quot;)

Checa_Validade_Registro:

If rstb.NoMatch = True Then
rsta.FindNext (&quot;PLACA > ''&quot;) 'get next record string
GoTo Checha_Validade_Placa
Else
If TempA = 0 Then
TempA = rstb!HODFINAL

Pega_Proximo_Registro:

rstb.FindNext (&quot;HODFINAL > 0&quot;) 'get next record
GoTo Checa_Validade_Registro
Else
TempB = rstb!HODINICIAL - TempA
CurrentDb.Execute &quot;UPDATE CAMPOS SET HODDIF = TempB&quot;
TempA = rstb!HODFINAL
GoTo Pega_Proximo_Registro
End If
End If
End If

Placa_Sem_Mais_Registros:

As_Placas_Acabaram:
MsgBox (&quot;as placas acabaram&quot;) 'this just show me the execution is finished
Exit Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top