Set focus

N

NNlogistics

I seem to have so much trouble with set focus. Does it trouble anyone else?
Maybe I dont understand what it does or maybe its the if /then I am using. I
have a very simple pop up form. it has 2 enties and I want to be sure that
there is data in those fields before I close the form.
If it detects a null, want it to stop and wait for input at the txtbox. It
doesn't, it just closes form. My guess is the if/then not the set focus but
I hope I will get other opinions.

Private Sub cmdToClosefrmRepairComplete_Click()
On Error GoTo Err_cmdToClosefrmRepairComplete_Click
If IsNull(txtDateRepairComplete) Then
MsgBox (" You must have an Entry in 'Date Repair Complete'")
Me.txtDateRepairComplete.SetFocus

End If



DoCmd.Close

Exit_cmdToClosefrmRepairComplete_Click:
Exit Sub

Err_cmdToClosefrmRepairComplete_Click:
MsgBox Err.Description
Resume Exit_cmdToClosefrmRepairComplete_Click

End Sub

I
 
K

Ken Snell [MVP]

Put an Exit Sub step right after the SetFocus step. Your code currently sets
the focus and then continues to the Close step.

If IsNull(txtDateRepairComplete) Then
MsgBox (" You must have an Entry in 'Date Repair Complete'")
Me.txtDateRepairComplete.SetFocus
Exit Sub
End If
 
N

NNlogistics

Thanks Ken

Ken Snell said:
Put an Exit Sub step right after the SetFocus step. Your code currently sets
the focus and then continues to the Close step.

If IsNull(txtDateRepairComplete) Then
MsgBox (" You must have an Entry in 'Date Repair Complete'")
Me.txtDateRepairComplete.SetFocus
Exit Sub
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top