Require field re-entry (1 Viewer)

ellenr

Registered User.
Local time
Today, 13:28
Joined
Apr 15, 2011
Messages
397
I have a program to keep scores in a team gin game. There are only two entry fields: "A" or "B" (TEAM) in the first field and the second field (SCORE) allows the points for the hand. The F1 posts the score to a "scratch pad". This is repeated for each pair of players, until all have finished at which time the F9 key is pressed to record the aggravate score. I want to check the value of SCORE at entry time--if it is greater than 120 then I want to clear the field and put the cursor back in the now nulled score box without exiting. I might add an uhoh sound but I don't want a popup error message. How do I do all of this before the F1 key is pressed? I can change the value to null "on exit" but since it only exits when the F1 post key is pressed, it is too late. This change isn't really necessary, but we have some fumble-fingered people entering scores sometimes and this would alleviate having to correct a score. It's a fun little program if you like gin--I will attach it in case you are interested.
 

Attachments

  • Gin.accdb
    1.9 MB · Views: 60

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:28
Joined
Feb 19, 2002
Messages
43,275
When the user presses the F1 key, add code to validate the entry, If it is invalid, display a message, put the cursor back in the data entry field and exit the sub without copying to the clipboard.
 

ellenr

Registered User.
Local time
Today, 13:28
Joined
Apr 15, 2011
Messages
397
I am trying to clear the invalid entry and eliminate the error message. I think I have figured out an easier way to accomplish what I want in the post macro, but still working on it. Thank you for your response--may go back to vba per your suggestion.
 

LarryE

Active member
Local time
Today, 10:28
Joined
Aug 18, 2021
Messages
591
I don't know what this is supposed to be, but it certainly is not a relational database. None of the tables are related in any way I can tell and it appears you are attempting to use numbers in text fields. Anyway, the score1 field that you are attempting to check to see if it is >120 is a text field and not a numeric field. ACCESS has no way of checking if a text field entry is > anything numeric. I was able to use the Score1 After Update event to check the value but it needed to be converted to a numeric value first and then checked.

I put this vba code in the score1 field After Update event:
Code:
Private Sub score1_AfterUpdate()
If CDbl(Me.score1) > 120 Then
    Me.score1 = Null
End If
End Sub

The CDbl function converts a text expression to a numeric value so it can be checked to see if it is >120
 

Attachments

  • Gin.accdb
    1.8 MB · Views: 64

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:28
Joined
Feb 19, 2002
Messages
43,275
If a field is defined as text then 2 will be > 120. Why??? Because text fields are compared character by character, left to right and 2 is > 1. Therefore, 2 is > 120

So, for starters always use the correct data type.
 

LarryE

Active member
Local time
Today, 10:28
Joined
Aug 18, 2021
Messages
591
If a field is defined as text then 2 will be > 120. Why??? Because text fields are compared character by character, left to right and 2 is > 1. Therefore, 2 is > 120

So, for starters always use the correct data type.
Use the whole program as it was intended...just sayin
 

ellenr

Registered User.
Local time
Today, 13:28
Joined
Apr 15, 2011
Messages
397
LarryE, I ended up using your vba code--works great, thank you. All of you are correct of course about the data type. As to whether this is a true relational database, it isn't but it was easiest way to write this program. It works, even for the total non-techie old ladies with whom I play gin. Thank you all for your replies.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:28
Joined
Feb 19, 2002
Messages
43,275
Use the whole program as it was intended...just sayin
Rather than hiding the problem by converting the string to a double (why a double rather than an integer is beyond me. There are no decimals in the scoring of Gin), I think underlying flaws in the design should be fixed. Unless you actually fix the things that are wrong with an app, you spend way too much time "fixing" the issues every time you write new code.

Just sayin

Clearly @ellenr didn't know what was causing the problem so I explained it. Hopefully, understanding the mistake , will prevent future similar mistakes.
 

LarryE

Active member
Local time
Today, 10:28
Joined
Aug 18, 2021
Messages
591
Rather than hiding the problem by converting the string to a double (why a double rather than an integer is beyond me. There are no decimals in the scoring of Gin), I think underlying flaws in the design should be fixed. Unless you actually fix the things that are wrong with an app, you spend way too much time "fixing" the issues every time you write new code.

Just sayin

Clearly @ellenr didn't know what was causing the problem so I explained it. Hopefully, understanding the mistake , will prevent future similar mistakes.
Exactly.
 

Users who are viewing this thread

Top Bottom