Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a code placed in a textbox got focus event.what it does is when it gets a focus it finds a value from a table and assigns it to the textbox.But if ther's no value it tells the user to define it and puts the focus on another control if the response is yes otherwise telling the user it can't proceed.

What i'm getting is,if there's no value and the response is yes it can't put the focus to that control and just loops the message.Any idea to break the loop if the response is yes.
VB
Dim dr As OleDb.OleDbDataReader = GetData(qry)
            If dr.HasRows = True Then
                Do While dr.Read
                    TextBox32.Text = dr.Item("total")
                    If Val(TextBox32.Text) > 800 Then
                        TextBox37.Text = Val(TextBox32.Text) - 800
                    Else
                        TextBox37.Text = 0
                    End If
                    TextBox38.Text = Val(TextBox36.Text) + Val(TextBox37.Text)
                    TextBox31.Text = (Val(TextBox33.Text) + Val(TextBox32.Text)) * Val(TextBox34.Text)
                Loop

            Else
                If MsgBox("Fuel allowance not defined for the current month of " & MonthName(currentdate.Month, False) & vbCrLf & _
                        "Do you want to define it?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Project Payroll") = MsgBoxResult.Yes Then
                    TextBox27.Focus()
                Else
                    MsgBox("Cannot define allowance without defining fuel allowance", MsgBoxStyle.Critical, "Project Payroll")
                    Exit Sub
                End If
            End If
Posted

I wouldn't use the GotFocus event at all, but put your code in the Validation event. Checking for invalid data is what that event is designed to do. By default, set the e.Cancel parameter to True, then once you have valid data, set it to False and all will proceed.
 
Share this answer
 
I just put the code in the Enter event of the textbox.
 
Share this answer
 
Comments
VICK 25-Jun-14 0:34am    
if you want to add any thing in your already posted question, than please use "Improve Question" option and if you want to add a comment over that, than please use "Have a Question or Comment?" option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900