START FROM THE FIRST DAY BASED TODAY

User avatar
sal21
PlatinumLounger
Posts: 4352
Joined: 26 Apr 2010, 17:36

START FROM THE FIRST DAY BASED TODAY

Post by sal21 »

i use this code to fill a combobox.

the code fill the combo with all day of the month.

But i need to fill the combo based the current day...

for example today 07/04/2022, start the list of day from 07/04/2022 to the and of last day of the month
for example today 02/04/2022, start the list of day from 02/04/2022 to the and of last day of the month
ecc...

Code: Select all

Private Sub FILL_GIORNI_1()

    Dim myVar As String
    Dim StartDate As Date
    Dim EndDate As Date
    Dim ThisDate As Date

    myVar = MESE & "-" & ANNO

    StartDate = CDate(myVar)
    EndDate = DateAdd("d", -1, DateAdd("m", 1, StartDate))

    With Me.CGIORNO2
        .Clear
        For ThisDate = StartDate To EndDate
            .AddItem UCase(Format$(ThisDate, "DDD")) & "-" & ThisDate
        Next
        Me.LNRG.Caption = .ListCount
    End With

End Sub

User avatar
HansV
Administrator
Posts: 78415
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: START FROM THE FIRST DAY BASED TODAY

Post by HansV »

Replace

Code: Select all

    myVar = MESE & "-" & ANNO

    StartDate = CDate(myVar)
with

Code: Select all

    StartDate = Date
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4352
Joined: 26 Apr 2010, 17:36

Re: START FROM THE FIRST DAY BASED TODAY

Post by sal21 »

HansV wrote:
07 Apr 2022, 20:32
Replace

Code: Select all

    myVar = MESE & "-" & ANNO

    StartDate = CDate(myVar)
with

Code: Select all

    StartDate = Date
Tks bro!
are of the dates for booking tables at the restaurant.
of course it is not possible to choose a date that has already passed :grin:
I think tuo have undestand me, naturally, or not?

User avatar
HansV
Administrator
Posts: 78415
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: START FROM THE FIRST DAY BASED TODAY

Post by HansV »

The code should do what you want.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 544
Joined: 27 Jun 2021, 10:46

Re: START FROM THE FIRST DAY BASED TODAY

Post by SpeakEasy »

Adopt Hans' change if "based the current day" , and then

Code: Select all

EndDate = DateSerial(Year(StartDate), Month(StartDate) + 1, 0)
Also I'd be temp;ted to change your AddItem to

Code: Select all

.AddItem UCase(Format(ThisDate, "ddd-dd/mm/yyyy"))

User avatar
sal21
PlatinumLounger
Posts: 4352
Joined: 26 Apr 2010, 17:36

Re: START FROM THE FIRST DAY BASED TODAY

Post by sal21 »

HansV wrote:
07 Apr 2022, 20:32
Replace

Code: Select all

    myVar = MESE & "-" & ANNO

    StartDate = CDate(myVar)
with

Code: Select all

    StartDate = Date
I need to use a month instead a day,.. how to?

for example:

if date is 05/05/2022

05-2022-month name
06-2022-month name
07-2022-month name
08-2022-month name
09-2022-month name
10-2022-month name
11-2022-month name
12-2022-month name
01-2023 month name
02-2023 month name
03-2023 month name
04-2023 month name

User avatar
HansV
Administrator
Posts: 78415
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: START FROM THE FIRST DAY BASED TODAY

Post by HansV »

Does this do what you want?

Code: Select all

Private Sub FILL_GIORNI_1()

    Dim StartDate As Date
    Dim i As Long

    StartDate = Date - Day(Date) + 1

    With Me.CGIORNO2
        .Clear
        For i = 0 To 11
            .AddItem UCase(Format(DateAdd("m", i, StartDate), "mm-yyyy-mmmm"))
        Next i
        Me.LNRG.Caption = .ListCount
    End With

End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4352
Joined: 26 Apr 2010, 17:36

Re: START FROM THE FIRST DAY BASED TODAY

Post by sal21 »

HansV wrote:
08 Apr 2022, 15:37
Does this do what you want?

Code: Select all

Private Sub FILL_GIORNI_1()

    Dim StartDate As Date
    Dim i As Long

    StartDate = Date - Day(Date) + 1

    With Me.CGIORNO2
        .Clear
        For i = 0 To 11
            .AddItem UCase(Format(DateAdd("m", i, StartDate), "mm-yyyy-mmmm"))
        Next i
        Me.LNRG.Caption = .ListCount
    End With

End Sub
:clapping: