Dim str1 As String
Dim str2 As String
Dim t As String
t = Nz(DMax("nomer", "baza", "id_patient_history=" & Forms![gamokvleva_gadaricxva_add]![idpatient_history]), 0) + 1
str1 = "INSERT INTO baza (id_patient_history, nomer, id_registration_test, id_top_test, fasi)" _
& " SELECT " & Forms![gamokvleva_gadaricxva_add]![idpatient_history] & ", " & t & ", R.id_registration_test, R.id_top_test, T.price" _
& " FROM top_test_sia_q AS T RIGHT JOIN registration_test_baza AS R ON T.id_top_test = R.id_top_test" _
& " WHERE R.id_registration_test=" & Me.id_registration_test & ";"
CurrentDb.Execute str1, dbFailOnError
str2 = "INSERT INTO baza_patient_tests (id_patient_history, id_registration_test, id_test, id_laboratory) " _
& " SELECT " & Forms![gamokvleva_gadaricxva_add]![idpatient_history] & ", RB.id_registration_test, test.id_test, test.id_laboratory" _
& " FROM registration_test_baza AS RB LEFT JOIN test ON RB.id_top_test = test.id_top_test" _
& " WHERE RB.id_registration_test=" & Me.id_registration_test & ";"
CurrentDb.Execute str2, dbFailOnError
If CurrentProject.AllForms("registratura_gadaricxva_newedit").IsLoaded Then
Dim d As Currency
d = DCount("[id_patient_history]", "patients_gamokvleva_sia_q", "[id_patient_history]=" & Forms![gamokvleva_gadaricxva_add]![idpatient_history])
Dim s As Currency
If (d = 0) Then
s = Me.SumOfprice
Else
s = Nz(Forms![registratura_gadaricxva_newedit]![sumtests]) + Nz(Me.SumOfprice)
End If
If IsNull(Forms![registratura_gadaricxva_newedit]![procent]) Then
Dim balance As Currency
balance = Nz(Forms![registratura_gadaricxva_newedit]![balance_tanxa]) - Nz(Me.SumOfprice)
Dim str4 As String
Dim str5 As String
If (balance >= 0) Then
str4 = "UPDATE patients_history SET patients_history.sum_gamokvlevis_tanxa = " & str(s) _
& ", patients_history.gadaricxvis_tanxa = " & str(s) _
& ", patients_history.balance_tanxa = " & str(balance) _
& " Where id_patient_history = " & Forms![gamokvleva_gadaricxva_add]![idpatient_history]
str5 = "UPDATE gadaricxva SET gadaricxva.balance = " & balance _
& " Where id_gadaricxva = " & Forms![registratura_gadaricxva_newedit]![idgadaricxva]
Else
Dim gt As Currency
Dim b As Currency
Dim n As Currency
gt = Nz(Forms![registratura_gadaricxva_newedit]![tanxa])
b = gt - s
n = b * (-1)
str4 = "UPDATE patients_history SET patients_history.sum_gamokvlevis_tanxa = " & str(s) _
& ", patients_history.gadaricxvis_tanxa = " & str(gt) _
& ", patients_history.balance_tanxa = " & str(b) _
& ", patients_history.natilobrivi_tanxa = " & str(n) _
& ", patients_history.salaros_tanxa = " & str(n) _
& " Where id_patient_history = " & Forms![gamokvleva_gadaricxva_add]![idpatient_history]
str5 = "UPDATE gadaricxva SET gadaricxva.balance = 0" _
& " Where id_gadaricxva = " & Forms![registratura_gadaricxva_newedit]![idgadaricxva]
End If
CurrentDb.Execute str4, dbFailOnError
CurrentDb.Execute str5, dbFailOnError
End If
Forms![registratura_gadaricxva_newedit]![registratura_gadaricxva_newedit_subform].Form.Requery
Forms![registratura_gadaricxva_newedit]![sumtests].Requery
Forms![registratura_gadaricxva_newedit]![summa].Requery
Forms![registratura_gadaricxva_newedit]![balance_tanxa].Requery
Forms![registratura_gadaricxva_newedit]![salaros_tanxa].Requery
Forms![registratura_gadaricxva_newedit]![natilobrivi_tanxa].Requery
End If
MsgBox "Запись добавлена"
|