Hi,
I have an app that I'm working on that enters a survey questionnaire. There are a number of fields that must be filled out if certain answers are given in previous fields. For example, if the answer "15" is selected in any of the three fields 151, 152, or 153, then field 15-2 must contain some answer.
Due to the number of possible error fields, and the fact that the operator could click any other field on the form instead of just tabbing or entering to the next sequential field, I wanted to set up a generic error trap so no matter what field the operator clicks on, if a previous required field was left empty, they would get a warning, then the cursor would move directly to that field. I started like this:
Dim blSkipError As Boolean
Dim strSkipField As String
Dim ctlSkipField As Control
... in the General Declarations. Then, as the operator makes a choice in the select field, I did this:
Private Sub Ctl151_Exit(Cancel As Integer)
blSkipError = True
strSkipField = "15-2"
Set ctlSkipField = Me!Ctl15_2
Me.Ctl152.Enabled = True
Me.Ctl152.SetFocus
End Sub
....
And this works fine, advancing through the three combo boxes until you arrive at field 15-2 (ctl15_2, as the code interprets the field name.) If the operator enters anything in that field, then the error condition is turned off, the variables are cleared, and we continue.
....
Next, in the On Enter event procedure for each field, I want to check blSkipError. If it's turned on, the code calls the generic error handling routine:
Private Sub Ctl16_Enter()
If blSkipError = True Then
Call SkipErrorHandler
End If
End Sub
This also works fine. The error handler routine is called, and the code runs.
BUT:
Public Sub SkipErrorHandler()
Dim Response As String
Response = MsgBox("Comments required in " & strSkipField, vbOKOnly)
If Response = vbOK Then
DoCmd.GoToControl (ctlSkipField.Name)
'DoCmd.GoToControl (ctlSkipField)
'DoCmd.GoToControl (strSkipField)
'DoCmd.GoToControl ("15-2")
'Me.Ctl15_2.SetFocus
End If
End Sub
Any one of these lines throws an error 2110, "Microsoft Office Access can't move the focus to the control 15_2."
Stepping through the code shows me that whenever one of those lines runs, code execution goes back and fires the Ctl151_Exit procedure again, even though I've tabbed to three other fields by this time. This is where the error occurs. So I can stop the error by removing the line in that procedure that sets the focus to 152 - but, since that's the next field in order, I want focus to go there the first time through the procedure - what I don't want is for the procedure to execute a second time, and if I remove all of the GoToControl or SetFocus statements in the error handler routine, Ctl151_Exit will not fire a second time.
I know this is probably confusing (it certainly is to me,) but does anyone have an idea as to what's going on here?
I have an app that I'm working on that enters a survey questionnaire. There are a number of fields that must be filled out if certain answers are given in previous fields. For example, if the answer "15" is selected in any of the three fields 151, 152, or 153, then field 15-2 must contain some answer.
Due to the number of possible error fields, and the fact that the operator could click any other field on the form instead of just tabbing or entering to the next sequential field, I wanted to set up a generic error trap so no matter what field the operator clicks on, if a previous required field was left empty, they would get a warning, then the cursor would move directly to that field. I started like this:
Dim blSkipError As Boolean
Dim strSkipField As String
Dim ctlSkipField As Control
... in the General Declarations. Then, as the operator makes a choice in the select field, I did this:
Private Sub Ctl151_Exit(Cancel As Integer)
blSkipError = True
strSkipField = "15-2"
Set ctlSkipField = Me!Ctl15_2
Me.Ctl152.Enabled = True
Me.Ctl152.SetFocus
End Sub
....
And this works fine, advancing through the three combo boxes until you arrive at field 15-2 (ctl15_2, as the code interprets the field name.) If the operator enters anything in that field, then the error condition is turned off, the variables are cleared, and we continue.
....
Next, in the On Enter event procedure for each field, I want to check blSkipError. If it's turned on, the code calls the generic error handling routine:
Private Sub Ctl16_Enter()
If blSkipError = True Then
Call SkipErrorHandler
End If
End Sub
This also works fine. The error handler routine is called, and the code runs.
BUT:
Public Sub SkipErrorHandler()
Dim Response As String
Response = MsgBox("Comments required in " & strSkipField, vbOKOnly)
If Response = vbOK Then
DoCmd.GoToControl (ctlSkipField.Name)
'DoCmd.GoToControl (ctlSkipField)
'DoCmd.GoToControl (strSkipField)
'DoCmd.GoToControl ("15-2")
'Me.Ctl15_2.SetFocus
End If
End Sub
Any one of these lines throws an error 2110, "Microsoft Office Access can't move the focus to the control 15_2."
Stepping through the code shows me that whenever one of those lines runs, code execution goes back and fires the Ctl151_Exit procedure again, even though I've tabbed to three other fields by this time. This is where the error occurs. So I can stop the error by removing the line in that procedure that sets the focus to 152 - but, since that's the next field in order, I want focus to go there the first time through the procedure - what I don't want is for the procedure to execute a second time, and if I remove all of the GoToControl or SetFocus statements in the error handler routine, Ctl151_Exit will not fire a second time.
I know this is probably confusing (it certainly is to me,) but does anyone have an idea as to what's going on here?