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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A SetFocus issue

Status
Not open for further replies.

jlathem

Technical User
Joined
Jul 25, 2010
Messages
27
Hey Guys,

I am having a problem with SetFocus.

What I am trying to do is check to se if the control Payee_ID is Null, if so give a MsgBox and SetFocus back to the Payee_ID control.

When I run the code below, I get the MsgBox and the curser blinks once or twice in Payee_ID before moving to the next tab stop.

Any suggestions?

Thanks,
James



Code:
Private Sub Payee_ID_LostFocus()
                
        'Declare page variable
         Dim var_NullCheck As Currency
    
        'Check to see if user entered Payee_ID, if not give message.
        If IsNull(Payee_ID) Then
            

             MsgBox "You must enter a Payee ID to continue." & vbCrLf & " " & vbCrLf & "Please Try Again.", vbExclamation
              
             Payee_ID.SetFocus
             
            
        Else
                
                'Find the DSum of all Rendering Provider's Total_Claims_Paid
                'If all Total_Claims_Paid values are Null replace with 0
                Me.Thirteen_Week_Average = Nz(DSum("Total_Claims_Paid", "Payee_Rendering_Claims_Data", "Payee_ID =" & Chr(34) & [Payee_ID] & Chr(34)), 0)
            
                'Find the Payee's Name form the Form's Payee_ID
                Me.Payee_Name = DLookup("Payee_Name", "Payee_Rendering_Claims_Data", "Payee_ID =" & Chr(34) & [Payee_ID] & Chr(34))
        End If
End Sub
 
You can't set the focus to a control that is losing the focus. Generally I just set the focus somewhere else and then back to the original control.

Duane
Hook'D on Access
MS Access MVP
 
Ah, well that makes dollars and senses!

Thanks for clearing that up for me.

Have a great day, um night!
James
 
How are ya jlathem . . .

A better spot for your code would be the controls [blue]On Exit[/blue] event. Here you can cancel the event and movement of the focus. Try:
Code:
[blue]   Dim var_NullCheck As Currency, [purple][b]DL[/b][/purple] As String
   
   [purple][b]DL[/b][/purple] = vbNewLine & vbNewLine
    
   If IsNull(Payee_ID) Then
      MsgBox "You must enter a Payee ID to continue." & [purple][b]DL[/b][/purple] & _
             "Please Try Again.", _
             vbExclamation, _
             "Payee ID Error! ..."
      [purple][b]Cancel = True[/b][/purple]
   Else[/blue]
Be sure to rem out or delete the code in the [blue]On Lost Focus[/blue] event to prevent interaction.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hey Thanks!

I’ll give that a try!

Ok in the interim, what’s the difference between “On Exit” and “On Lost Focus”? I know it’s a newbie question!

Thanks for the advice and the help!

James
 
jlathem said:
[blue] ... what's the difference between "On Exit" and "On Lost Focus"?[/blue]
The [blue]On Exit[/blue] event has a [blue]cancel[/blue] arguement you can use to cancel the event. The [blue]On Lost Focus[/blue] event does not!

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
If that's all then there really isn't any point in using the On Lost Focus.

Hummmm

Thanks for your help.

James
 
jlathem . . .

Except that for [blue]On Exit[/blue] focus hasn't moved yet ...

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Ah, ok.

Thanks for the info.

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top