Solved Make command button appear only 1 day a month (1 Viewer)

donkey9972

Registered User.
Local time
Today, 12:31
Joined
May 18, 2008
Messages
30
Hi,

I have a form with a command button on it, and I need it to only appear on the 1st day of every month and hidden every other day. I have no idea how to accomplish this at all, so I have no code to start with. I have googled and searched forums but I am having no luck with my search. I have found a way to make something flash on and off, but that is the most advanced my search came up with (for me this was a huge accomplishment. Any ideas for my current issue though?
 

Eugene-LS

Registered User.
Local time
Today, 22:31
Joined
Dec 7, 2018
Messages
481
Any ideas for my current issue though?
Code:
Private Sub Form_Current()
    If Day(Date) = 1 Then
        Me.cmdYourCommandButtonName.Enabled = True ' = 1st day of every month
        'Or:
        Me.cmdYourCommandButtonName.Visible = True
    Else
        Me.cmdYourCommandButtonName.Enabled = False
        'Or:
        Me.cmdYourCommandButtonName.Visible = False
    End If
End Sub
 

isladogs

MVP / VIP
Local time
Today, 19:31
Joined
Jan 14, 2017
Messages
18,186
Similar to above but use the Load event, make the button hidden / disabled by default and you can then omit the Else section
It could be done like this:

Code:
Private Sub Form_Load()
     Me.cmdYourCommandButtonName.Visible = Day(Date) = 1 'only visible on 1st day of every month
End Sub
 

isladogs

MVP / VIP
Local time
Today, 19:31
Joined
Jan 14, 2017
Messages
18,186
A quick translation for anyone interested....! 😎

1650451775459.png
 

donkey9972

Registered User.
Local time
Today, 12:31
Joined
May 18, 2008
Messages
30
That worked perfectly thank both. All the help has gotten what I needed accomplished.
 

donkey9972

Registered User.
Local time
Today, 12:31
Joined
May 18, 2008
Messages
30
Similar to above but use the Load event, make the button hidden / disabled by default and you can then omit the Else section
It could be done like this:

Code:
Private Sub Form_Load()
     Me.cmdYourCommandButtonName.Visible = Day(Date) = 1 'only visible on 1st day of every month
End Sub
Okay, so doing it this way, I have 2 other buttons I need to make invisible on the 1st only. How would I get that done using the one line of code? I figured out how to do it using Eugene-LSs code, but without the true/false ability I have no idea how to make it work.
 

moke123

AWF VIP
Local time
Today, 15:31
Joined
Jan 11, 2013
Messages
3,852
Can't help but to ask, What is this button for? What happens if the 1st is on a Sunday or some day you're not available to click it?
 

isladogs

MVP / VIP
Local time
Today, 19:31
Joined
Jan 14, 2017
Messages
18,186
Never mind I figured it out. :)
Its always helpful to others if you supply your solution
For example, with cmdButton1 hidden by default & cmdButton2 & cmdButton3 made visible by default, then

Code:
Private Sub Form_Load()
    Me.cmdButton1.Visible = Day(Date) = 1
    Me.cmdButton2.Visible = Not (Day(Date) = 1)
    Me.cmdButton3.Visible = Not (Day(Date) = 1)
End Sub

If you have another good solution, please post it.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:31
Joined
Sep 21, 2011
Messages
14,046
What happens if the computer is not on when it is the first of the month?, bank holiday etc?
 

moke123

AWF VIP
Local time
Today, 15:31
Joined
Jan 11, 2013
Messages
3,852
What happens if the computer is not on when it is the first of the month?, bank holiday etc?
My guess is the OP is resetting something for the upcoming month not realizing that it could be automated without any user intervention.
 

donkey9972

Registered User.
Local time
Today, 12:31
Joined
May 18, 2008
Messages
30
What happens if the computer is not on when it is the first of the month?, bank holiday etc?
Honestly that is not an issue, there is always someone in the building 365 days a year, 366 on leap years.
 

moke123

AWF VIP
Local time
Today, 15:31
Joined
Jan 11, 2013
Messages
3,852
The reason we ask follow up questions is to get a better sense of what it is your doing. Its very likely what your doing can be done without any user intervention.

Edit: Now that I see your other post it would seem you have a data problem.
 
Last edited:

Users who are viewing this thread

Top Bottom