SetFocus

  • Thread starter Thread starter DCPan
  • Start date Start date
D

DCPan

Hi all,

I set a condition on a textbox so that on "when exit", it will see if
another textbox value is zero, and if the value is not zero, see if the
textbox is null, otherwise, set the cursor back to the textbox.

The if then statements do work as the msgbox is triggered to notify the user
that comments need to be entered when the value isn't zero.

But the setfocus isn't working and it isn't a typo...what's up?

Private Sub DailyComments_Exit(Cancel As Integer)

'Set up Error Handling Tracer
strModule = "Form_frm_DailyVariance"
strProcedure = "DailyComments_Exit"

'Error Handling
On Error GoTo ErrorFlow

'Check to see if a comment is needed
If Me.DailyVariance <> 0 Then

'Check to see if there are any comments
If IsNull(Me.DailyComments) Then

MsgBox "You must explain why the daily variance is not zero in
the
comment section!", _
vbInformation, "Clarification needed!"

'Set focus on the comment box
Me.DailyComments.SetFocus

End If

End If

Exit_Code:

Exit Sub

ErrorFlow:

'Use Global_Error_Handler
HandleError Err.Number, Err.Description, strModule, strProcedure, True

'Exit Error Handler
Resume Exit_Code

End Sub
 
Hi all,

I set a condition on a textbox so that on "when exit", it will see if
another textbox value is zero, and if the value is not zero, see if the
textbox is null, otherwise, set the cursor back to the textbox.

The if then statements do work as the msgbox is triggered to notify the user
that comments need to be entered when the value isn't zero.

But the setfocus isn't working and it isn't a typo...what's up?

Private Sub DailyComments_Exit(Cancel As Integer)

'Set up Error Handling Tracer
strModule = "Form_frm_DailyVariance"
strProcedure = "DailyComments_Exit"

'Error Handling
On Error GoTo ErrorFlow

'Check to see if a comment is needed
If Me.DailyVariance <> 0 Then

'Check to see if there are any comments
If IsNull(Me.DailyComments) Then

MsgBox "You must explain why the daily variance is not zero in
the
comment section!", _
vbInformation, "Clarification needed!"

'Set focus on the comment box
Me.DailyComments.SetFocus

End If

End If

Exit_Code:

Exit Sub

ErrorFlow:

'Use Global_Error_Handler
HandleError Err.Number, Err.Description, strModule, strProcedure, True

'Exit Error Handler
Resume Exit_Code

End Sub

Incorrect event.
Use the control's BeforeUpdate event, not it's Exit event.

Then, instead of:
'Set focus on the comment box
Me.DailyComments.SetFocus

Write:
' Return to the Comment Box without updating
Cancel = True
 
Hi Fred,

You rock.

The event was actually correct, but the cancel = true did the trick. I
needed the exit event because I didn't want the user to click away without
entering something.

Thanks again!
 
Back
Top