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

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.

I think it would be more elegant to use the HTML5 placeholder approach, where if there is no value in the table, you would put something like "put a value", and make sure at validation of the textbox that a correct value was entered, or delete whatever was there. If you don't like the placeholder, you could add a label next to the textbox and set that to visible if there is no value in the table.

Good luck.

The problem is that you are leaving the control to ask the user to enter a value and when you get back to the textbox the got-focus event fires again. If the only valid response to "Do you want to define a value" is "Yes" then why do you ask the question. You should just say "You must define a value to continue. In that case you could do something like display a message in a label like "You must enter a value to continue" and set the background colour of the textbox to red to highlight it. Just make sure that you don't leave the user stuck in the control.

Instead of locking the user in the control you could display a modal dialog box prompting the user to enter a value and testing when the dialog is closed for a valid value or cancel and taking the appropriate action.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.