Solved Get Min and Max Date and insert Into Property (1 Viewer)

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
Hi guys,

I am not really sure how to achieve this in the easiest way.
What I like to achieve is to get min Date of a table and max Date of the same table and create a FileName out of it.

Code:
Private m_startDate As String
Private m_endDate As String
Private m_year As String
Private m_fileName As String
'

Public Property Let StartDate(ByVal datStart As Date)
    m_startDate = datStart
End Property
Public Property Get StartDate() As Date
    StartDate = m_startDate
End Property

Public Property Let EndDate(ByVal datEnd As Date)
    m_endDate = datEnd
End Property
Public Property Get EndDate() As Date
    EndDate = m_endDate
End Property

Public Property Let StatYear(ByVal datYear As Date)
    m_year = datYear
End Property
Public Property Get StatYear() As Date
    StatYear = m_year
End Property

Public Property Let FileName(ByVal strFileName As String)
    m_fileName = strFileName
End Property
Public Property Get FileName() As String
    FileName = m_fileName
End Property

Sub test()
    StartDate = #1/4/2022#
    EndDate = #12/31/2022#
    StatYear = #12/31/2022#
    FileName = Format(StartDate, "MMM") & Format(EndDate, "MMM") & Format(StartDate, "YYYY")

    Debug.Print FileName
End Sub

I import a File which has in one field all dates...

So do I need to create a query for the Start Date and one for the End Date with Min and Max function or is there a better way?

Do I even need all those Properties or can I short cut it in a better way?

Hope someone could help me with this.

Many thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:37
Joined
May 7, 2009
Messages
16,775
to be honest you don't need those.
it would be of value if you are creating a class or something.
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
I do have a class where I import the file, so how would it then be better could you explain please?
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:37
Joined
Sep 21, 2011
Messages
10,838
What is wrong with DMin() & DMax() ?
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
not sure :)
So would you create a Query to return the min and max Value of the date and then save the value in a property or create a function to return it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:37
Joined
Sep 21, 2011
Messages
10,838
not sure :)
So would you create a Query to return the min and max Value of the date and then save the value in a property or create a function to return it?
They are builtin Access functions?
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
yes I know that but in context to be able to retrieve it.

Should I create two queries one for the StartDate and one for the EndDate, or can you return it straigt away in a property?
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:37
Joined
Sep 21, 2011
Messages
10,838
Return it straight away?
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
I mean is there a way to retrieve the date within the properties or is that not something you do or can do?
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
Or how would you go about it?
You have a table you import into Access. And you like to create a FileName out of it.

The FileName should then be something like JanToDez2021.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:37
Joined
Oct 29, 2018
Messages
19,134
Or how would you go about it?
You have a table you import into Access. And you like to create a FileName out of it.

The FileName should then be something like JanToDez2021.
Maybe something like?
Code:
FileName = Format(DMin("DateField","TableName"),"mmm") & "To" & Format(DMax("DateField","TableName"),"mmmyyyy")
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
Hi DBguy,
thanks for your reply!!

this in a Property you mean?
Property Get I guess...
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
Hey,

it works just like that fine!!
Of course I need to put it in the Property Let first!

Code:
Public Property Let EasyFileName(ByVal strTable As String)
     m_easyFileName = Format(DMin("Buchungsdatum", strTable), "mmm") & "To" & Format(DMax("Buchungsdatum", strTable), "mmmyyyy")
End Property
Public Property Get EasyFileName() As String
    EasyFileName = m_easyFileName
End Property

Cool :cool:

Many thanks to all and of course to you theDbGuy ;-)
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:37
Joined
Oct 29, 2018
Messages
19,134
Hey,

it works just like that fine!!
Of course I need to put it in the Property Let first!

Code:
Public Property Let EasyFileName(ByVal strTable As String)
     m_easyFileName = Format(DMin("Buchungsdatum", strTable), "mmm") & "To" & Format(DMax("Buchungsdatum", strTable), "mmmyyyy")
End Property
Public Property Get EasyFileName() As String
    EasyFileName = m_easyFileName
End Property

Cool :cool:

Many thanks to all and of course to you theDbGuy ;-)
Hi. Glad to hear you got it to work. We were all happy to assist. Good luck with your project.
 

silentwolf

Member
Local time
Today, 03:37
Joined
Jun 12, 2009
Messages
353
Thank you!!

Yes it is really fantastic all the help I get here!

It is very much appreciated and I can learn alot from you guys!

Cheers again!
 

Users who are viewing this thread

Top Bottom