PDA

Click to See Complete Forum and Search --> : Can a LostFocus event be selective? i.e Don't activate if this happens.


Al Smith
Jan 25th, 2000, 07:11 AM
Hi,
I'm trying to use the LostFocus on a couple of text boxes to auto-populate some other text boxes. Everything works ok as long as valid data is entered. But I'm trying to trap invalid input. Here's the gist of the program.

Text1 "Enter Warehouse Code".

When Text1 loses focus Text2, the warehouse name, is populated from a database.

Text3 "Enter Part Number"

When Text3 loses focus Text4, the part description, is populated from a database.

The problem is if an invalid warehouse code is entered. If the warehouse code doesn't exist in the database a message box pops up stating "Warehouse Code XXXXX Invalid". But the focus has moved to Text3 via the [TAB] key. When you back-tab to Text1 to correct the warehouse code, Text3 loses focus and tries to find a blank part number in the database. A message box pops up stating "Part Number Invalid".

Question 1: Can I make a losefocus event happen except if something else happens?

Question 2: Is there a better way of doing what I'm trying to do?

Thanks,
Al.


------------------
A computer is a tool, not a toy.
<A HREF="mailto:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

jpark
Jan 25th, 2000, 08:15 AM
You can make a flag to indicate validation of input.


'On the Form Module
private flagInvalidInput as Boolean

Private Sub txtWHCode_LostFocus()

'Code for getting Warehouse Name

If [Invalid Warehouse code] then
Msgbox "Invalid Code"
flagInvalidInput = True
txtWHCode.SetFocus
else
flagInvalidInput = False
end if
End Sub

Private Sub txtPartNo_LostFocus()
If Not flagInvalidInput then
'Code for getting Part Description goes here

If [Invalid Part Number] then
Msgbox "Invalid Part Number"
txtPartNo.SetFocus
end if

end if
End Sub

You can use ComboBoxes for the Warehouse Code and Part Number instead of TextBoxes.

Get the warehouse code and the part number on Form Load events and put it into comboBoxes.

If you set Style to 2-DropDown List, user are not able to type anything other than what's already in the combobox list.

This way you can avoid invalid input from user, and user don't need to remember whole warehouse code or part number.

Joon

Al Smith
Jan 25th, 2000, 09:00 AM
Hi,
Thank you for your suggestion, however I'm still getting the same situation. Whether the focus moves from Text3 to Text1 via a back-tab or programatically the LostFocus event for Text3 is still launched.

I thought of combo boxes but I'm dealing with 125 warehouses and over 2500 part numbers.

Thanks,
Al.


[This message has been edited by Al Smith (edited 01-25-2000).]

Al Smith
Jan 25th, 2000, 09:50 AM
Man! This is getting complicated. I can kind of get this to work by setting the tabstop property of the text boxes to false and letting the program select the next box if the input is valid. But I also have command buttons which clears the form, sends the data from the form to an E-mail address (Winsock), or returns to the main menu. If one of these are pressed while Text1 or Text3 has focus the LostFocus event is activated.
I'm just starting to try to write programs with forms so that others can use them. Trying to perceive and trap all potential user generated errors is quite a challenge.

Thanks,
Al.


------------------
A computer is a tool, not a toy.
<A HREF="mailto:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

jpark
Jan 25th, 2000, 12:52 PM
Sorry if that didn't work out.
If you post your code, it'll be better for me to fix the problem.

However, try this example.


' You need 4 TextBoxes

Private flgInvalidInput As Boolean

Private Sub Text1_LostFocus()
GetWHName Trim(Text1.Text)
End Sub

Private Sub Text3_LostFocus()
If Not flgInvalidInput Then
GetPartDesc Trim(Text3.Text)
Else
MsgBox "Invalid Input"
Text3.SetFocus
End If
End Sub

Private Sub GetWHName(parCode As String)
If parCode = "" Then
Text2 = "No Action"
ElseIf parCode = "x" Then
Text2 = "Invalid Input"
MsgBox "Invalid Input. Try again"
Text1.SetFocus
flgInvalidInput = True
Else
Text2 = "Name found for " & parCode
Text3.SetFocus
flgInvalidInput = False
End If
End Sub

Private Sub GetPartDesc(parPartNo As String)
If parPartNo = "" Then
Text4 = "No Action"
ElseIf parPartNo = "x" Then
Text4 = "Invalid Input"
MsgBox "Invalid Input. Try again"
Text3.SetFocus
flgInvalidInput = True
Else
Text4 = "Description found for " & parPartNo
Text1.SetFocus
flgInvalidInput = False
End If
End Sub


Joon