The first thought I have on this is that Access gets to the close command
before it has finished the calculation and this causes the crash.
One thing to try is to put these 2 lines directly before the DoCmd.Close
DoEvents
DoEvents
If that doesn't help, posting all the code for the click event of the
close
button would help us to help you.
Jeanette Cunningham
Jeanette,
Since the crash occurs even when I go thru the code line-by-line, I
don't think that your supposition is the answer. The code (somewhat
simplified for brevity) follows
rivate Sub Button25_Click()
On Error GoTo Err_Button25_Click
DoCmd.SetWarnings False
Dim MySQL As String, MySQL1 As String, MySQL2 As String, Dt As String,
i As Integer
Dim DB As DAO.Database, rst As DAO.Recordset, rst1 As DAO.Recordset,
rst2 As DAO.Recordset, rst3 As DAO.Recordset, MySQL3 As String
Dim rst4 As DAO.Recordset, Mysql4 As String, Mysql5 As String, MySQL6
As String, MySQL7 As String, cp As Currency, D As Currency
Dim Precharges As Currency, Answer As Date, Answer1 As String, FeeReg
As Currency
DoCmd.Hourglass True
'SAVE RECORD
DoCmd.DoMenuItem A_FORMBAR, A_FILE, A_SAVERECORD, , A_MENU_VER20
'Then select all of "services" for this pt and for this insco# and
change
'values to new insco#, insaddress and insindex
'SET EARLIEST DATE FOR EFFECTIVE CHANGE
If Not IsNull(DMin("[Date_From]", "Services", "[patient ID#] = Forms!
[FInsuranceInfoEdit]![patient ID#] and Forms![FInsuranceInfoEdit]!
[SelectInsco]")) Then
Dt = DMin("[Date_From]", "Services", "[patient ID#] = Forms!
[FInsuranceInfoEdit]![patient ID#] and Forms![FInsuranceInfoEdit]!
[SelectInsco]") '??????
Else
MsgBox "No Services entered to correct"
DoCmd.Close acForm, "FInsuranceInfoEdit", acSaveYes
DoCmd.Hourglass False
Exit Sub
End If
DoCmd.Beep
Answer = InputBox$("First Svc Date for this patient is " & Dt & ":" &
Chr(13) & Chr(10) & "Enter effective date of this insurer correction"
& Chr(13) & Chr(10) & "Enter in format mm-dd-yyyy", , Dt)
Me![Effective Policy Date] = Format(Answer, "mm-dd-yyyy")
'UPDATE SERVICES SO THAT MONETARY DATA IS BLANK IN RST
MySQL2 = "UPDATE DISTINCTROW SERVICES SET SERVICES.lineinsurer =
[Forms].[FInsuranceInfoEdit].[SelectInsco], " & _
"SERVICES.[InsIndex#] = [Forms].[FInsuranceInfoEdit].[PolicyType], " &
_
"SERVICES.AddIndex = [Forms].[FInsuranceInfoEdit].[InsAddress], " & _
"SERVICES.linecoinsurer = [Forms].[FInsuranceInfoEdit].
[SelectCoinsco], " & _
"SERVICES.[CoInsIndex#] = [Forms].[FInsuranceInfoEdit].[CoPolicyType],
" & _
"SERVICES.CoAddIndex = [Forms].[FInsuranceInfoEdit].[CoInsAddress], "
& _
"SERVICES.AnnDeductCovered = [Forms].[FInsuranceInfoEdit].
[AnnDeductCovered], " & _
"SERVICES.ProceduralDeduct = [Forms].[FInsuranceInfoEdit].[ProcedureCo-
pay], " & _
"SERVICES.OfficeProcedureAmt = [Forms].[FInsuranceInfoEdit].
[OfcProcedureCo-PayFee], " & _
"SERVICES.HospProcedureAmt = [Forms].[FInsuranceInfoEdit].
[HospProcedCo-PayFee], " & _
"SERVICES.PayCatID = [Forms]![FInsuranceInfoEdit].[PayCatID], " & _
"SERVICES.Precharges = 0, SERVICES.Charges = 0, SERVICES.[Charges adj]
= 0, " & _
"SERVICES.ChargesApproved = 0, SERVICES.AnnualDeduct = 0,
SERVICES.deductapplied = 0, SERVICES.ProcedureDeductApplied = 0, " & _
"SERVICES.PreAnticPay = 0, SERVICES.PreAnticPay1 = 0,
SERVICES.PreAnticPay2 = 0, SERVICES.AnticPay = 0, " & _
"SERVICES.PatientOwes = 0, SERVICES.AnticCopay = 0, SERVICES.CoPay =
0, SERVICES.QUamt = 0 " & _
"WHERE (((SERVICES![Patient ID#])=[Forms].[FInsuranceInfoEdit].
[Patient ID#]) " & _
"AND ((SERVICES.Date_From) >=[Forms].[FInsuranceInfoEdit].[Effective
Policy Date])); "
DoCmd.RunSQL MySQL2
'RST for correction is SET HERE
Set DB = CurrentDb()
MySQL = "SELECT DISTINCTROW Services.* " & _
"FROM Services " & _
"WHERE (Services.lineinsurer= " & Me![SelectInsco] & ") " & _
"AND (Services.[Patient ID#]= " & Me![Patient ID#] & ") " & _
"AND (Services.Date_From >= " & Me![Effective Policy Date] & ") " & _
"ORDER BY Services.INVLINNUM;"
Set rst = DB.OpenRecordset(MySQL, dbOpenDynaset)
g = rst.RecordCount
If g > 0 Then
'SET PRECHARGES & CHARGES
Dim Insurance_Co As String, CCode As String, Days As Integer,
Modifiers As Integer, Billyear As Integer, fil As String
'determine linnumber of item
'find data for DLookup--insurance co name
rst.MoveFirst
Do Until rst.EOF
If rst!Mod1 = "26" Or rst!Mod1 = "TC" Then
c = rst!CPTCode & rst!Mod1
ElseIf rst!Mod2 = "26" Or rst!Mod2 = "TC" Then
c = rst!CPTCode & rst!Mod2
Else: c = rst!CPTCode
End If
y = DatePart("yyyy", rst!Date_From)
x = rst!paycatID
Select Case Val(x) ' Test input.
'note that several cases are omitted from code for brevity
Case 1, 4, 10, 11 'Medicare type 'ELIMINATE #3-Managed Care
'normal fee comes before lopay = -1
'if regular pay line is null, then fill in prices before rest of line
finishes
If IsNull(DLookup("[fee]", "FeeSchedCare", "[CPTCode] = '" & c
& "' And [year] ='" & y & "' And [lopay] = 0 ")) Then
'seek record where cpt code = C & lopay = no
DoCmd.OpenForm "FFeeSchedCare", , , ("[CptCode] = '" & c & "'
And [year] ='" & y & "' And [lopay] = 0 ")
End If
rst.Edit
If rst![Place of svc] <> 11 Then
If Not IsNull(DLookup("[fee]", "FeeSchedCare", "[CPTCode]
='" & c & "' And [year] = '" & y & "' And [lopay] = -1 ")) Then
rst!Precharges = DLookup("[fee]", "FeeSchedCare",
"[CPTCode] ='" & c & "' And [year] = '" & y & "' And [lopay] = -1 ")
ElseIf IsNull(DLookup("[fee]", "FeeSchedCare", "[CPTCode]
='" & c & "' And [year] = '" & y & "' And [lopay] = -1 ")) Then
rst!Precharges = DLookup("[fee]", "FeeSchedCare",
"[CPTCode] = '" & c & "' And [year] ='" & y & "' And [lopay] = 0 ")
End If
ElseIf rst![Place of svc] = 11 Then
rst!Precharges = DLookup("[fee]", "FeeSchedCare",
"[CPTCode] = '" & c & "' And [year] ='" & y & "' And [lopay] = 0 ")
rst.update
End If
Case 9
Msg = "Enter value for this miscellaneous charge"
MsgBox Msg ' Display message.
Exit Sub
End Select
rst.MoveNext
Loop
'SET CHARGE
rst.MoveFirst
Do Until rst.EOF
rst.Edit
If rst!Units = 1 Then
If rst!Mod1 = "50" Or rst!Mod2 = "50" Or rst!Mod3 = "50" Or
rst!Mod4 = "50" Then
rst!Charges = rst![Precharges] * 1.5
ElseIf rst!Mod1 = "53" Or rst!Mod2 = "53" Or rst!Mod3 = "53"
Or rst!Mod4 = "53" Then
rst!Charges = rst![Precharges] * 0.5
Else: rst!Charges = rst!Precharges
End If
ElseIf rst!Units <> 1 Then
rst![Charges] = rst![Precharges] * (rst!Units)
End If
rst.update
rst.MoveNext
Loop
The rest of these calculation steps are simply other examples of If--
Then and Do---loop sequences to perform calculations to set values of
rst fields. (Details have been omitted)
'Step2 'applydeduct 'sets [preanticpay]
'Step 3 apply co-pay
'Step4 'SetCoPayProcedural
'sets value of copayment for procedures for certain insurers
' setpercentpay 'step5
'Step6
'This sets [PatientOwes] and [AnticCoPay]
'Set QU value Step 7
'billdetailsupdate Step8
'finalize Step9
DoCmd.SetWarnings False
rst.MoveFirst
Do Until rst.EOF
MySQL7 = "UPDATE DISTINCTROW TBillDetails SET TBillDetails.InitBD1 =
Null, TBillDetails.LastBD1 = Null "
MySQL7 = MySQL7 & "WHERE TBillDetails.linenum = " & rst!LineNum & ";"
DoCmd.RunSQL MySQL7
rst.MoveNext
Loop
DoCmd.SetWarnings True
End If
rst.Close
DoCmd.SetWarnings True
DoCmd.Hourglass False
'THIS IS WHERE APPLICATION CRASHES
DoCmd.Close
Exit_Button25_Click:
Exit Sub
Err_Button25_Click:
MsgBox Error$
Resume Exit_Button25_Click
End Sub