Date formatting

Solved
Ouistiti73 Posted messages 18 Status Member -  
Ouistiti73 Posted messages 18 Status Member -
Hello,
I have a form with a date of birth. In the table, it is recorded in the format dd/mm/yyyy.
For the applicant, the day and month don’t matter for now, he would like to have 01/01/ and only the year to be filled in. I looked at the different formats, but I think I'll need to create a macro. I will only provide the year and then, with the macro, set the day and month to 01.
What do you think, and if you have the code and the way to do it, I would appreciate it.
Have a good evening
PS however, I do not want to modify the day and month for already created entries.

Configuration: Windows / Firefox 88.0

11 answers

yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
 
Hello, what is the field type in the table?
You don’t say anything about your form, nor how the form triggers the creation of a record.
You might be able to use the DateSerial function to convert the year into a date, for example:
DateSerial(2054,1,1)
0
Ouistiti73 Posted messages 18 Status Member
 
Hello, Thank you for your quick response.
This is a form to update a Member table, in this table there is a field Born on -
(by the way, I don’t like this field name, but it’s not me who created this database). I am just making some modifications and fixing certain issues.
The format for Born on is Date, general and the format is 00/00/00;0;_
The user would like to only enter the year during registration and have it store 01/01/1972 for example in the table.
However, he wants to keep the birthday dates for already created members because if we have to roll back, only the new ones would need to be modified.
There is a button “New Registration” with this content on click:

Private Sub Commande193_Click()
On Error GoTo Err_Commande193_Click

DoCmd.GoToRecord , , acNewRec
If Month(Date) < 8 Then
INSCRADH = Year(Date) - 1

Else
INSCRADH = Year(Date)

End If
[Insen cours] = DLookup("[AnnéeCours]", "Current Year")

Me.CivADH.SetFocus
Me.Code_intervenant = 1

Exit_Commande193_Click:
Exit Sub

Err_Commande193_Click:
MsgBox Err.Description
Resume Exit_Commande193_Click

End Sub

The date format in the form is plain text with an input mask 00/00/00;0;_

I would like the cursor to directly land on
the year type 01/01/???? during a new record and in modification, it’s not grave, we rarely modify birthday dates, unless there’s an error. And thus in the table we would obtain 01/01/1972
I hope this is clear to you.
Thank you

It has been a long time since I practiced and I have forgotten many things and learned a lot of new techniques. Style on point on the main table and clicking on the form and there magic appears.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
You did not answer my question, can you confirm that the type of the field "born on" is "Date/Time"? The format generally matters very little.

I think the cleanest option would be to create a year field in the table, instead of recording a false date of birth in this case.

Otherwise, adding a control
year of birth
in the form, and when this control is modified, update the value of the
born on
control in the form.
0
Ouistiti73 Posted messages 18 Status Member
 
Yes, sorry, I forgot to specify it's indeed "Date/Time".
She doesn't want another field, I asked her.
What I thought was to modify the form. Replace the "born on" field with "YearOfBirth" and after modification, it creates 01/01/Year entered in the "YearOfBirth" field and updates the "born on" field which could remain in the form as non-visible. (I’m not sure if it needs to appear on the form or not for it to be updated)
The day they want to return to the full entry, just change this field back to "born on".
What do you think? However, since dates can sometimes result in strange things, I’m not sure how to handle that.
This relates to your second point. I can keep both visible but only allow the "YearOfBirth" field of the form to be modified.
0
Ouistiti73 Posted messages 18 Status Member
 
Hello,

How to create an independent field in a form to record a value that will be the year of birth and be able to use VBA to write "born on 01/01/year of birth"?
Thank you.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
Can you share your file?
0
Ouistiti73 Posted messages 18 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
 
Hello, I have minimized my database, but I don't know how to send it to you. It's the first time.
Thank you
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > Ouistiti73 Posted messages 18 Status Member
 
You need to publish the file on the internet (Google Drive, One Drive, cjoint.com, ...) and then share a link to the published file here.
0
Ouistiti73 Posted messages 18 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
 
https://accounts.google.com/ServiceLogin?service=wise&passive=1209600&continue=https://drive.google.com/file/d/1vUGeyH1_WIwEMUyks8HbGDmzQMxD0HOt/view?usp%3Dsharing&followup=https://drive.google.com/file/d/1vUGeyH1_WIwEMUyks8HbGDmzQMxD0HOt/view?usp%3Dsharing

Hoping for good reception.
Actually, I only want to enter a birth year and force 01/01 for the day and month to fill my born (e) field.
This way, if one day we want to go back, it will be possible to restore the born (e) field.
Thank you.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > Ouistiti73 Posted messages 18 Status Member
 
The file is not public.
0
Ouistiti73 Posted messages 18 Status Member
 
Good evening
Yes, I would like to, but which file in an Access database?
Thank you
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
Do you have several?
0
Ouistiti73 Posted messages 18 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
 
Hello, I have minimized my database, but I don't know how to send it to you. It's the first time.
Thank you
0
castours
 
Bonsoir,
you will find in this link a compressed file with different date formats.
Let me know.
0
Ouistiti73 Posted messages 18 Status Member
 
Thank you.
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
 
Here is the translation: Here is my proposal:
- create a new control of type "text box" named "andn" in the form, intended to contain the year of birth
- make the control named "Né__e_" read-only (or hide it, but do not delete it)
- add this code to the form:
Private Sub Form_Current() If Not IsNull(Me.Né__e_) Then Me.andn = Year(Me.Né__e_) Else Me.andn = Null End If End Sub Private Sub andn_AfterUpdate() If Not IsNull(andn) Then If IsNumeric(andn) Then If Int(andn) = CSng(andn) And Int(andn) > 0 Then Me.Né__e_ = DateSerial(andn, 1, 1) End If End If End If End Sub
0
Ouistiti73 Posted messages 18 Status Member
 
Super, cela répond exactement à mes besoins, j'ai rajouté un masque de saisie : 0000;;_ à ce champ "andn" de façon qu'il ne tape que 4 chiffres.
Je ne connaissais pas le code CSng ou je ne m'en souviens plus c'est tellement loin la programmation.
J'aimerai bien que vous me l'expliquiez, par contre est-il utile du fait que j'ai mis un masque de saisie ?
Grand merci à vous
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
csng() converts the text into a number (of type
single
).
As you guessed, lines 10, 11, 13, and 14 are unnecessary in the presence of this input mask. They check that the text is a positive integer.
I added them after removing the input mask I had initially created, not knowing if you could or wanted to use such a mask (especially to avoid explaining the mask).
0
Ouistiti73 Posted messages 18 Status Member
 
Okay, that's what I did. The mask is better, otherwise they'll put a comma on me by mistake or something.
Thank you
0
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
 
Can you then mark the discussion as resolved?
0
Ouistiti73 Posted messages 18 Status Member
 
I will come back later about another problem if I can't solve it, it's for inserting a photo into my form.
See you soon.
0