Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set focus on text box in header 1

Status
Not open for further replies.

spizotfl

MIS
Aug 17, 2005
345
US
hi, i have a text box in the form header that i want the user to enter a value into. i have the following code:
Code:
Private Sub JJID_LostFocus()
    If Trim(Me.JJID) & "" = "" Then
        MsgBox "You must enter a JJID before proceeding"
        Me.JJID.SetFocus
    End If
End Sub
but if i click on another control, i get the message, but the focus goes to the other control.
any thoughts?
 
How about:
Code:
Private Sub JJID_LostFocus()
    If Trim(Me.JJID) & "" = "" Then
        MsgBox "You must enter a JJID before proceeding"
        Me.OtherBox.SetFocus
        Me.JJID.SetFocus
    End If
End Sub
 
Anyway to avoid problems with null value use this:
If Trim(Me.JJID & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
that works, but now i realized that if i do that, then if i just want to close the form without entering anything, i still get the message, any ideas?
thanks
btw, star for the code!
 
May be change your message to "You have not ... Click OK to continue or Cancel to Exit"?
 
remou, good idea to add the msgbox and user interaction. i added in a test for the msgbox value and put that if the user selects cancel that i want the form to close, but i get a "This action cannot be carried out while processing a form or report event."
Code:
    If Trim(Me.JJID) & "" = "" Then
        response = MsgBox("You have not entered a JJID." & vbCrLf & _
            "Ok to continue Cancel to Exit", vbOKCancel, "Enter JJID")
        If response = vbOK Then
            Me.SchoolEnrolled.SetFocus
            Me.JJID.SetFocus
        Else
            DoCmd.Close
        End If
    End If
 
Hmm, it was a very bad suggestion :-(, you cannot close a form in a focus event. Here is another idea:
Code:
If MsgBox("You have not entered a JJID." & vbCrLf & _
            "Ok to continue Cancel to Exit", vbOKCancel, "Enter JJID")=vbOk Then
'What ever
Else

  Me.AllowEdits = False
  Me.AllowAdditions = False

  Me.cmdClose.SetFocus
End If
Not great, though.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top