I am getting a Type Mismatch (Run-Time 13) error on a form close action. The continuous form pulls in a small group of related records that need to be checked/edited (by opening specific records on a single record form). The Close button Click() action runs two update queries (successfully) prior to the error. There are no other calculations and all the data are loaded/unloaded on other forms without a hitch. I cannot figure out why the error is being generated and am hoping someone can ask me the right question to trigger a resolution. My code is straightforward. I added line numbers so I could use ‘Debug.Print Erl’ in the error handling to find the dubious line, and it tells me it is line 30, on the form closure. I’ve added a bit more background below, in case it helps.
Code:
Private Sub btnCloseAllegs_Click()
10 On Error GoTo Err_btnCloseAllegs_Click
20 DoCmd.SetWarnings False
22 DoCmd.OpenQuery "1qryUpdateAllegationCaseInfo"
24 DoCmd.OpenQuery "2qryUpdateAllegationCaseInfo"
26 DoCmd.SetWarnings True
30 DoCmd.Close"frmDiffAllegationsCheck"
40 DoCmd.OpenForm"frmAllegationChooseList"
100 Exit_btnCloseAllegs_Click:
Exit Sub
110 Err_btnCloseAllegs_Click:
MsgBoxErr.Description
Debug.PrintErl
ResumeExit_btnCloseAllegs_Click
End Sub
Background:
I had a pretty straightforward macro that ran with OnClick()of a closeForm command button. The macro created some temporary variables to update other related records, then ran two separate saved queries to 1) update dates, and 2) update locations, then closed the current form, and opened the next form. Not all related records/fields always need to be updated, so I have a “lock” which is a Yes/No. If that field is “Yes” the first query updates the date fields, but not the locations for those records. If it is “No” the first query updates dates and the second updates locations. All that worked fine both before and after my changes.
I inserted a subroutine that checks for “Yes” records and if they exist, pulls them to a new form so the user can verify the information for those records. I broke the macro described above into two sections. Before the subroutine, I set the tempVars and close the current form. If there are ‘Yes’ records, the subroutine opens. If not, or after they are updated and the user clicks to close the form, the second half of the macro runs: the 2 queries update dates and locations where appropriate, the form closes (*Error here), and the next form opens.