Solved Error with Input Mask

zelarra821

Registered User.
Local time
Today, 07:25
Joined
Jan 14, 2019
Messages
835
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

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
 
It must be two years, like football season. I don't know if you understand me.
 
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.
 
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
 
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.
 
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

Back
Top Bottom