setfocus doesnt work

B

Bre-x

I have this code on a text box control (tfind) How come the focus does not
go back to it? It goes to the next control
There is something wrong with my code, but i cannt see it.

Thnks


Private Sub tfind_LostFocus()
Dim sqlstring As String, mymsg As String
If IsNull(Me.tfind) = True Then
Exit Sub
End If
Me.Mainsub.SourceObject = "Blank"
sqlstring = "SELECT count(*) as CC FROM BKARINV WHERE BKAR_INV_SONUM = " &
Me.tfind
CurrentDb.QueryDefs("DBA").SQL = sqlstring

If DLookup("[CC]", "DBA") = 0 Then
mymsg = "Sales Order: " & Me.tfind & " is not on DBA."
Responce = MsgBox(mymsg, vbCritical, " UMC")
Me.tfind.SetFocus
Exit Sub
End If
End Sub
 
R

RuralGuy

I have this code on a text box control (tfind) How come the focus does not
go back to it? It goes to the next control
There is something wrong with my code, but i cannt see it.

Thnks


Private Sub tfind_LostFocus()
Dim sqlstring As String, mymsg As String
If IsNull(Me.tfind) = True Then
Exit Sub
End If
Me.Mainsub.SourceObject = "Blank"
sqlstring = "SELECT count(*) as CC FROM BKARINV WHERE BKAR_INV_SONUM = " &
Me.tfind
CurrentDb.QueryDefs("DBA").SQL = sqlstring

If DLookup("[CC]", "DBA") = 0 Then
mymsg = "Sales Order: " & Me.tfind & " is not on DBA."
Responce = MsgBox(mymsg, vbCritical, " UMC")
Me.tfind.SetFocus
Exit Sub
End If
End Sub
Validation of entries in controls is usually done in the BeforeUpdate event and
Cancel=True is used to hold the focus in the current event.
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
B

Bre-x

That explained it!!
To make it work I had to bound the form and the control. ......That create
another set of problems.

Thanks for your help, now the focus stays where i want it.

Regards,

Bre-x



RuralGuy said:
I have this code on a text box control (tfind) How come the focus does not
go back to it? It goes to the next control
There is something wrong with my code, but i cannt see it.

Thnks


Private Sub tfind_LostFocus()
Dim sqlstring As String, mymsg As String
If IsNull(Me.tfind) = True Then
Exit Sub
End If
Me.Mainsub.SourceObject = "Blank"
sqlstring = "SELECT count(*) as CC FROM BKARINV WHERE BKAR_INV_SONUM = " &
Me.tfind
CurrentDb.QueryDefs("DBA").SQL = sqlstring

If DLookup("[CC]", "DBA") = 0 Then
mymsg = "Sales Order: " & Me.tfind & " is not on DBA."
Responce = MsgBox(mymsg, vbCritical, " UMC")
Me.tfind.SetFocus
Exit Sub
End If
End Sub
Validation of entries in controls is usually done in the BeforeUpdate
event and
Cancel=True is used to hold the focus in the current event.
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 

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

Similar Threads


Top