Option Compare Database
Sub RunAllFunctions()
On Error GoTo ErrorHandler
' Call each of the functions
InsertIntoUhrada
UpdateValuesFA
UpdateValuesHO
' Display a message indicating that all functions have been executed
MsgBox "All functions executed successfully."
Exit Sub
ErrorHandler:
MsgBox "An error occurred: " & Err.Description, vbCritical
End Sub
Sub InsertIntoUhrada()
Dim db As DAO.Database
Dim strSQL As String
' Initialize the database object
Set db = CurrentDb()
' Construct the SQL query
strSQL = "INSERT INTO Uhrady (DatumU, RelAgH, RelIDH, CisloH, VarSymH, RelAgU, RelIDU, CisloU, KcU, CmH, CmU) " & _
"SELECT FA.Datum, 2, FA.ID, FA.VarSym, FA.VarSym, 27, HO.ID, HO.Cislo, FA.KcCelkem, FA.KcCelkem, FA.KcCelkem " & _
"FROM FA " & _
"INNER JOIN HO ON FA.VarSym = HO.ParSym " & _
"WHERE FA.ID NOT IN (SELECT RelIDH FROM Uhrady);"
' Execute the query
db.Execute strSQL, dbFailOnError
' Close the database
db.Close
' Release the database object
Set db = Nothing
' Display a message box indicating successful execution
MsgBox "Data inserted into Uhrady table."
End Sub
Sub UpdateValuesFA()
Dim db As DAO.Database
Dim strSQL As String
' Initialize the database object
Set db = CurrentDb()
' Construct the SQL query to update FA values
strSQL = "UPDATE FA " & _
"SET FA.KcLikv = 0, FA.KcU = FA.KcCelkem " & _
"WHERE FA.ID IN (SELECT RelIDH FROM Uhrady);"
' Execute the query to update FA values
db.Execute strSQL, dbFailOnError
' Close the database
db.Close
' Release the database object
Set db = Nothing
End Sub
Sub UpdateValuesHO()
Dim db As DAO.Database
Dim strSQL As String
' Initialize the database object
Set db = CurrentDb()
' Construct the SQL query to update HO.KcLikv and HO.KcU
strSQL = "UPDATE HO " & _
"SET HO.KcU = HO.KcCelkem " & _
"WHERE HO.ID IN (SELECT RelIDU FROM Uhrady) AND HO.KcU = 0 ;"
' Execute the query to update HO.KcLikv and HO.KcU
db.Execute strSQL, dbFailOnError
' Release the database object
Set db = Nothing
Exit Sub
End Sub