![]()
Name: InventoryFields.JPG Views: 18 Size: 11.6 KB ID: 9732" class="thumbnail" style="float:CONFIG" />
Access 2007, VBA, Windows 2007 64 bit, skill level intermediate, single user, compiled, not split.
Tab order. When the form opens the Tab1=PU On Hand
Tab2=IU On Hand
I think I have a problem with my basic strategy. I need a more graceful solution. I am working on the inventory portion of a database. When the Master Inventory screen opens the Tab order takes the end user to the "PU on Hand" field. They should only be able to enter Zero or a Positive Integer. My three tests will catch the error and notify the end user, and then I start having problems in trying to end this gracefully.
I have tried my code in the "Before Update" event, and in the "On Exit" event. I've tried me.undo which has its problems. I currently have the code inserting Zero when there is an error. But then the code ends and the tab order of the screen takes them to the next field "IU on Hand." I don't know how to get the Tab Order stopped, and not advance to the next field until the correct data is entered. My code entering a Zero is not really a good idea as the end user will just roll on not fully realizing the data meets the test but isn't really correct. When they are tabbed to the IU on Hand and enter the Individual Units on hand it takes the numbers from the PU on Hand, calculates with the IU on Hand and enters the new Inventory Value in the extentions field. See attached screen snap.
When the data is correct my code works fine and gives me the right numbers and calculations.
When the data is not correct such as NULL, Negative, or a Fraction my my code works fine and detects it and notifies the end user.
When the data is not correct i am struggling to find the best way to handle it.
Here is my code:
Private Sub PUOnHand_Exit(Cancel As Integer)
If IsNull(Me.PUOnHand) = True Then
Call MsgBox("The PU On Hand field cannot be empty." _
& vbCrLf & "You must enter 0, or any positive, whole number." _
& vbCrLf & "Please re-enter the number." _
, vbCritical, "Field Empty")
Me.PUOnHand = 0
Exit Sub
End If
If (Me.PUOnHand) < 0 Then
Call MsgBox("The PU On Hand field cannot be negative." _
& vbCrLf & "You must enter 0, or any positive, whole number." _
& vbCrLf & "Please re-enter the number." _
, vbCritical, "Negative Number")
Me.PUOnHand = 0
Exit Sub
End If
If Me.PUOnHand <> Int(Me.PUOnHand) Then
Call MsgBox("The PU On Hand field cannot be a fraction." _
& vbCrLf & "You must enter 0, or any positive, whole number." _
& vbCrLf & "Please re-enter the number." _
, vbCritical, "Fraction")
Me.PUOnHand = 0
Exit Sub
End If
End Sub
I'm not sure what to ask here except my solution detects the problem but doesn't really help the end user to put in the right data. I'm going to run into the same problem with the IUperPU field when they get there.
Thanks,
Phred