Solved Error with Input Mask (1 Viewer)

zelarra821

Registered User.
Local time
Today, 19:14
Joined
Jan 14, 2019
Messages
813
Hi guys.

I am attaching an example database on which I am going to explain what I want to achieve.

I have the Season field, to which I have an input mask:

0000/0000;0;_

The user must enter the season in this way: 2024/2025, and if he enters it in another way, he must give an error, hence he uses the input mask. So far, no problems.

Now, I would like to ensure that if the user enters 2024 and goes to the next record, it is filled by adding a year to 2024 to show 2024/2025, but without losing the input mask. Everything I tried to achieve this gives me the input mask error.

Let's see if someone can help me solve this problem.

Thank you so much.
 

Attachments

  • Database.accdb
    640 KB · Views: 17

arnelgp

..forever waiting... waiting for jellybean!
Local time
, 01:14
Joined
May 7, 2009
Messages
19,247
maybe add code to the Change event?
 

Attachments

  • Database (1).accdb
    960 KB · Views: 16

CJ_London

Super Moderator
Staff member
Local time
Today, 18:14
Joined
Feb 19, 2013
Messages
16,622
If the season is always a year why bother with the second year? You can just have a calculated value in a second control

=[season] + 1
 

zelarra821

Registered User.
Local time
Today, 19:14
Joined
Jan 14, 2019
Messages
813
It must be two years, like football season. I don't know if you understand me.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:14
Joined
Feb 28, 2001
Messages
27,197
It must be two years, like football season. I don't know if you understand me.

The ONLY possible misunderstanding is whether there could EVER be a split season as 2024/2026 (skipping a year). If not, entering the first year automatically defines the second year, in which case why bother to require its entry? In fact, why bother to even STORE it? You can recompute it in a query or on a form or report simply by knowing the first year.

Asking someone to enter both years is asking too much if you can never have a split non-contiguous season.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:14
Joined
Feb 19, 2013
Messages
16,622
It must be two years, like football season. I don't know if you understand me.
Understand perfectly, just asking why do it that way? Your way what is to stop the user entering 2924/1950? So you need validation to check they actually enter two ‘valid’ years

my way you only need to validate one year and the user doesn’t need to spend time entering a second year

seems to me you are making it more complicated than it needs to be

I write a lot of accounting apps where the accounting year end (not start) is specified. Kind of opposite to your requirement

Easy enough to determine the year start from the year end
 

zelarra821

Registered User.
Local time
Today, 19:14
Joined
Jan 14, 2019
Messages
813
It's possible to do what I want if you use this input mask:

and then you insert this code: 9999/9999;0;_ (9 is optional and 0 is required).

Code:
Private Sub Temporada_AfterUpdate()

    If IsNumeric(Left(Me.Temporada, 4)) And Right(Me.Temporada, 1) = "/" And Len(Me.Temporada) = 5 Then

        Me.Temporada = Me.Temporada & (Left(Me.Temporada, 4) + 1)

    Else

        MsgBox "Incorrect year."
        Me.Temporada = ""

    End If

End Sub

Thanks to everybody.
 

June7

AWF VIP
Local time
Today, 09:14
Joined
Mar 9, 2014
Messages
5,479
Usually BeforeUpdate event is used for data validation.

I never allow empty string in fields so I would not set control equal to "", but to Null.
 

Users who are viewing this thread

Top Bottom