Fuddrucker
Aug 18 2004, 11:27 AM
I want to enter data into fields and check the values. This is what I want to do:
(1) Enter the data
(2) Check for proper values
(3) If improper, give a feedback message
(4) After user clicks on "OK" on the feedback message, leave the cursor in the data field and wait for another attempt. Ignore all enter and tab keypress events until the proper response is given, unless the ESC key is pressed to escape.
(5) When proper reponse is received and after enter, or tab, go to the next field.
I've figured out out to do (1), (2), and (3). But on (4), the cursor goes to the next field rather than staying at the original data entry field.
I can't use the Validation Rule because it doesn't work properly when I reference other fields in the forumula. (Access help on VBA also says: "In addition, field validation rules can't contain references to other fields. "). I also want to mix regular and bold fonts in the error message, and the Validatioin Text doesn't seem to allow that either.
I suspect I need to use a combination of Data Events, but I can't figure out which ones. Is there a reference I can use to learn more about controlling data events for entering data?
Here is the function I've written so far to accomplish the above. I'm using the "after update" data event but I suspect that's the wrong one. The other data events don't get the job done, either.
Thanks!
Private Function CheckCValue(AptNo As Long, CValue As Variant) As Variant
CheckCValue = CValue
If Not IsNull(CValue) Then
If IsNumeric(CValue) Then
If AptNo <> 999 Then
If IsNull(Me.nLastName1) Then
CheckCValue = Null
Eval ("MsgBox ('The value you entered isn''t valid for this field @unless you " & _
"first enter a ""Resident A"" name when an apartment number other than 999 is [email=used.@@']used.@@'[/email], 64, 'Rent Management System')")
End If
End If
Else
CheckCValue = Null
Eval ("MsgBox ('The value you entered isn''t valid for this [email=field.@You]field.@You[/email] need to input a numeric [email=value.@@']value.@@'[/email], 64, 'Rent Management System')")
End If
End If
End Function
balaji
Aug 18 2004, 12:26 PM
You can use the setfocus method to set the focus to the input element that had bad data in it. You can read up on setfocus in the VBA help files.
Fuddrucker
Aug 18 2004, 03:52 PM
balaji:
After reflecting on the "setfocus" method, I'm still at a loss as to how to accomplish my data input objectives. Can you offer any other reference material?
Thanks!
balaji
Aug 18 2004, 04:25 PM
Well, you are stuck on point 4 from your original post. Let us say you have a control called myControl which you are checking for input from the user. The user enters a value. In the afterupdate() event of the control you would have this code:
CODE
private sub myControl_afterupdate()
if not isvalid(me.myControl) then 'isvalid() would be a function you would write to check whether the entered data is valid or not
me.mycontrol = null 'Clear the invalid input
me.mycontrol.setfocus 'You put the cursor back in this control for the user to try again
msgbox("You entered an invalid input for myControl",vbOK)
end if
end sub
If this does not meet your needs, I would be happy to help you out further if you can define more clearly what exactly you are after.
Fuddrucker
Aug 18 2004, 07:55 PM
I still have the same problem: after the error message and the control is set to null after an incorrect entry, the cursor moves to the next field. The "Me.mycontrol.setfocus" doesn't seem to affect the outcome one way or another. Here is my code:
Private Sub nR1AppFee_AfterUpdate()
If Not IsValidC(Me.nR1AppFee) Then
Me.nR1AppFee = Null
Me.nR1AppFee.SetFocus
End If
---------------------------------
Private Function IsValidC(CValue As Variant) As Boolean
IsValidC = True
If Not IsNull(CValue) Then
If IsNumeric(CValue) Then
If Me.AptNo <> 999 Then
If IsNull(Me.nLastName1) Or Me.nLastName1 = "" Then
Eval ("MsgBox ('The value you entered isn''t valid for this field @unless you " & _
"first enter a ""Resident A"" name when an apartment number other than 999 is [email=used.@@']used.@@'[/email], 64, 'Rent Management System')")
IsValidC = False
End If
End If
Else
Eval ("MsgBox ('The value you entered isn''t valid for this [email=field.@You]field.@You[/email] need to input a numeric [email=value.@@']value.@@'[/email], 64, 'Rent Management System')")
IsValidC = False
End If
End If
End Function
--------------------
Commenting out the MsgBox in the function does not affect the outcome, either. The above is basically the code you recommended. What am I missing?
In response to your question, what I am after is to accomplish the 5 steps explained in my initial post.
Thanks for your help!
balaji
Aug 20 2004, 11:41 AM
That is very weird. Try the following:
Private Sub nR1AppFee_AfterUpdate()
If Not IsValidC(Me.nR1AppFee) Then
Me.nR1AppFee = Null
me.someothercontrol.setfocus
Me.nR1AppFee.SetFocus
End If
End sub
someothercontrol is just some other control on the form. I have heard that sometimes you have to do that to get the focus back to the control which the user was on originally.
Fuddrucker
Aug 20 2004, 12:27 PM
That did it! You don't know how many hours I've been messing with this problem. So, it seems like it's a "personality trait" in Access I wasn't aware of.
Thanks a million!
o! o! o! o!
balaji
Aug 20 2004, 02:47 PM
You are welcome. Typical of MS products, Access also has some undocumented "features"! Good luck with the rest of your project.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.