|
-
Jan 25th, 2000, 08:11 AM
#1
Thread Starter
Hyperactive Member
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:[email protected]
[email protected]">[email protected]
[email protected]</A>
-
Jan 25th, 2000, 09:15 AM
#2
Member
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
-
Jan 25th, 2000, 10:00 AM
#3
Thread Starter
Hyperactive Member
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).]
-
Jan 25th, 2000, 10:50 AM
#4
Thread Starter
Hyperactive Member
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:[email protected]
[email protected]">[email protected]
[email protected]</A>
-
Jan 25th, 2000, 01:52 PM
#5
Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|