N
newuser44
Hi -
I am having some trouble with some VBA code on a form. Basically the form
brings in patient abnormality data and in order to link these data to a
biopsy of the abnormality I run a SQL append query to create a new row in a
table that contains abnormality id and biopsy id. On the form users can
checkbox a variety of abnormalities and then I run a series of SQL statements
to update the table accordingly. What I would like to do is assign a value
of 1 to the variable MadeError if the error handler is used during the
process, so that my append query is not run in the event of an error.
Here is the relevant code:
The code that runs the append query:
If Me!Abn5.Value = True Then
Debug.Print MadeError
Call GoTo5
RunBx1 = "INSERT INTO AbnBiopsy (PENRAD_ABNORMALITY_ID, MedicalID) " & _
"VALUES (" & [multmatch_qry_allabn_sub1].Form!PENRAD_ABNORMALITY_ID &
"," & [multmatch_qry_bx subform1].Form!MedicalID & ");"
Debug.Print RunBx1
Debug.Print MadeError
If MadeError = 0 Then DoCmd.RunSQL RunBx1
End If
The code the identifies the location on the viewable subform:
Public Sub GoTo5() 'for the 5th row
Dim MadeError As Long
'error handling
On Error GoTo Err_Click
'select second record on current subform list
Forms![MultipleMatcher]![multmatch_qry_allabn_sub1].SetFocu
Forms![MultipleMatcher]![multmatch_qry_allabn_sub1].Form.Controls!PENRAD_ABNORMALITY_ID.SetFocus
DoCmd.GoToRecord , , acFirst
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
Exit_Click:
Debug.Print "made error after goto"
MadeError = 1
Debug.Print MadeError
Exit Sub
Err_Click:
MsgBox Err.Description
Resume Exit_Click
End Sub
When I run this when a error should occur I get the following in the
immediate window:
0
made error after goto
1
INSERT INTO AbnBiopsy (PENRAD_ABNORMALITY_ID, MedicalID) VALUES (63372,3440);
0
As you can see, MadeError gets set to 0 after my docmd.run sql, and I'm not
sure why....
any help would be appreciated!
I am having some trouble with some VBA code on a form. Basically the form
brings in patient abnormality data and in order to link these data to a
biopsy of the abnormality I run a SQL append query to create a new row in a
table that contains abnormality id and biopsy id. On the form users can
checkbox a variety of abnormalities and then I run a series of SQL statements
to update the table accordingly. What I would like to do is assign a value
of 1 to the variable MadeError if the error handler is used during the
process, so that my append query is not run in the event of an error.
Here is the relevant code:
The code that runs the append query:
If Me!Abn5.Value = True Then
Debug.Print MadeError
Call GoTo5
RunBx1 = "INSERT INTO AbnBiopsy (PENRAD_ABNORMALITY_ID, MedicalID) " & _
"VALUES (" & [multmatch_qry_allabn_sub1].Form!PENRAD_ABNORMALITY_ID &
"," & [multmatch_qry_bx subform1].Form!MedicalID & ");"
Debug.Print RunBx1
Debug.Print MadeError
If MadeError = 0 Then DoCmd.RunSQL RunBx1
End If
The code the identifies the location on the viewable subform:
Public Sub GoTo5() 'for the 5th row
Dim MadeError As Long
'error handling
On Error GoTo Err_Click
'select second record on current subform list
Forms![MultipleMatcher]![multmatch_qry_allabn_sub1].SetFocu
Forms![MultipleMatcher]![multmatch_qry_allabn_sub1].Form.Controls!PENRAD_ABNORMALITY_ID.SetFocus
DoCmd.GoToRecord , , acFirst
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acNext
Exit_Click:
Debug.Print "made error after goto"
MadeError = 1
Debug.Print MadeError
Exit Sub
Err_Click:
MsgBox Err.Description
Resume Exit_Click
End Sub
When I run this when a error should occur I get the following in the
immediate window:
0
made error after goto
1
INSERT INTO AbnBiopsy (PENRAD_ABNORMALITY_ID, MedicalID) VALUES (63372,3440);
0
As you can see, MadeError gets set to 0 after my docmd.run sql, and I'm not
sure why....
any help would be appreciated!