T
Tony Williams
I have a procedure that runs three queries, 2 update queries and 1 append
query. These queries need to be run before a report is produced from the
database. However it is possible that the user will edit records after the
procedure is run and this will mean that the procedure will have to be rerun
to recreate the updated report. However because this adds duplicate records
from the append query. How can I change my code so that the queries will
only run on records that have been changed since it was last run? Here is my
code:
Private Sub cmdupdatedata_Click()
On Error GoTo Err_cmdupdatedata_Click
'Step1 Update Euro records
Dim stDocName1 As String
stDocName1 = "qryYTDUpdateIrisha"
'Step2 Update UK data
Dim stDocName2 As String
stDocName2 = "qryYTDUpdatea"
'Step3 update UK data with Euro data
Dim stDocName3 As String
stDocName3 = "qryeurovaluea"
Dim Msgstr1 As String
Dim Msgstr2 As String
Dim Msgstr3 As String
Msgstr1 = "You are about to:" & vbCrLf _
& "1. Update the records for the Euro zone companies by calculating the
quarterly data from the YTD data" & vbCrLf _
& "2. Update the records for the UK companies " _
& "by calculating the quarterly data from the YTD data" & vbCrLf _
& "3. Add the Euro company data to the UK data" & vbCrLf _
& "(HAVE YOU CREATED THE NEW EURO RATE RECORD FOR THIS QUARTER?)" &
vbCrLf & vbCrLf _
& "Are you sure you want to do all of this?"
Msgstr2 = "To update the data you must enter the current quarter!"
Msgstr3 = "To update the data you must enter the previous quarter!"
Me.txtqtr2.SetFocus
If Nz(Me.txtqtr2.Text) <> "" Then
Me.txtqtr3.SetFocus
If Nz(Me.txtqtr3.Text) <> "" Then
If MsgBox(Msgstr1, vbYesNo, "Updating all UK and Euro data") = vbNo Then
DoCmd.Close
Else
DoCmd.OpenQuery stDocName1, acNormal, acEdit
DoCmd.OpenQuery stDocName2, acNormal, acEdit
DoCmd.OpenQuery stDocName3, acNormal, acEdit
End If
Else
MsgBox Msgstr3, vbOKOnly, "Missing Previous Quarter"
Me.txtqtr3.SetFocus
End If
Else
MsgBox Msgstr2, vbOKOnly, "Missing Current Quarter"
Me.txtqtr2.SetFocus
End If
Exit_cmdupdatedata_Click:
Exit Sub
Err_cmdupdatedata_Click:
MsgBox Err.Description
Resume Exit_cmdupdatedata_Click
End Sub
Thanks for any help
Tony
query. These queries need to be run before a report is produced from the
database. However it is possible that the user will edit records after the
procedure is run and this will mean that the procedure will have to be rerun
to recreate the updated report. However because this adds duplicate records
from the append query. How can I change my code so that the queries will
only run on records that have been changed since it was last run? Here is my
code:
Private Sub cmdupdatedata_Click()
On Error GoTo Err_cmdupdatedata_Click
'Step1 Update Euro records
Dim stDocName1 As String
stDocName1 = "qryYTDUpdateIrisha"
'Step2 Update UK data
Dim stDocName2 As String
stDocName2 = "qryYTDUpdatea"
'Step3 update UK data with Euro data
Dim stDocName3 As String
stDocName3 = "qryeurovaluea"
Dim Msgstr1 As String
Dim Msgstr2 As String
Dim Msgstr3 As String
Msgstr1 = "You are about to:" & vbCrLf _
& "1. Update the records for the Euro zone companies by calculating the
quarterly data from the YTD data" & vbCrLf _
& "2. Update the records for the UK companies " _
& "by calculating the quarterly data from the YTD data" & vbCrLf _
& "3. Add the Euro company data to the UK data" & vbCrLf _
& "(HAVE YOU CREATED THE NEW EURO RATE RECORD FOR THIS QUARTER?)" &
vbCrLf & vbCrLf _
& "Are you sure you want to do all of this?"
Msgstr2 = "To update the data you must enter the current quarter!"
Msgstr3 = "To update the data you must enter the previous quarter!"
Me.txtqtr2.SetFocus
If Nz(Me.txtqtr2.Text) <> "" Then
Me.txtqtr3.SetFocus
If Nz(Me.txtqtr3.Text) <> "" Then
If MsgBox(Msgstr1, vbYesNo, "Updating all UK and Euro data") = vbNo Then
DoCmd.Close
Else
DoCmd.OpenQuery stDocName1, acNormal, acEdit
DoCmd.OpenQuery stDocName2, acNormal, acEdit
DoCmd.OpenQuery stDocName3, acNormal, acEdit
End If
Else
MsgBox Msgstr3, vbOKOnly, "Missing Previous Quarter"
Me.txtqtr3.SetFocus
End If
Else
MsgBox Msgstr2, vbOKOnly, "Missing Current Quarter"
Me.txtqtr2.SetFocus
End If
Exit_cmdupdatedata_Click:
Exit Sub
Err_cmdupdatedata_Click:
MsgBox Err.Description
Resume Exit_cmdupdatedata_Click
End Sub
Thanks for any help
Tony