Solved Checkboxes with Yes / No (1 Viewer)

Rania01

Member
Local time
Today, 22:51
Joined
Oct 9, 2021
Messages
59
Dear All,

I have a form where I have a 7 checkboxes. I want if the value on DateToday the same as the value on FirstDate
the checkboxes must be uncheck els check.

please help how to resolved this issue, I use below VBA

Code:
Option Explicit

Private Sub Form_Load()

If Me.DateToday.Value = Me.FirstDate.Value Then

Me.Monday.Enabled = False
Me.Tuesday.Enabled = False
Me.Wednesday.Enabled = False
Me.Thursday.Enabled = False
Me.Friday.Enabled = False
Me.Saturday.Enabled = False
Me.Sunday.Enabled = False

Else

Me.Monday.Enabled = True
Me.Tuesday.Enabled = True
Me.Wednesday.Enabled = True
Me.Thursday.Enabled = True
Me.Friday.Enabled = True
Me.Saturday.Enabled = True
Me.Sunday.Enabled = True


End If

End Sub
 

Attachments

  • Printschr.jpg
    Printschr.jpg
    35 KB · Views: 83
  • Data.zip
    47.2 KB · Views: 107

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:51
Joined
May 7, 2009
Messages
19,245
Code:
you set it's Value property not it's Enabled property:

Option Explicit

Private Sub Form_Load()

If Me.DateToday.Value = Me.FirstDate.Value Then

Me.Monday = False
Me.Tuesday = False
Me.Wednesday = False
Me.Thursday = False
Me.Friday = False
Me.Saturday = False
Me.Sunday = False

Else

Me.Monday = True
Me.Tuesday = True
Me.Wednesday = True
Me.Thursday = True
Me.Friday = True
Me.Saturday = True
Me.Sunday = True


End If

End Sub

you also need to Run the code on the Current Event of your Form.
 

Rania01

Member
Local time
Today, 22:51
Joined
Oct 9, 2021
Messages
59
Dear Arnelgp,

I just Add below VBA on Current Event en not working

Code:
Option Explicit

Private Sub Form_Current()

If Me.DateToday.Value = Me.FirstDate.Value Then

Me.Monday.Enabled = False
Me.Tuesday.Enabled = False
Me.Wednesday.Enabled = False
Me.Thursday.Enabled = False
Me.Friday.Enabled = False
Me.Saturday.Enabled = False
Me.Sunday.Enabled = False

Else

Me.Monday.Enabled = True
Me.Tuesday.Enabled = True
Me.Wednesday.Enabled = True
Me.Thursday.Enabled = True
Me.Friday.Enabled = True
Me.Saturday.Enabled = True
Me.Sunday.Enabled = True


End If

End Sub
 

Rania01

Member
Local time
Today, 22:51
Joined
Oct 9, 2021
Messages
59
Dear arnegp,

Sorry now is working thank you you are the best​

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 19, 2002
Messages
43,281
Any time your process requires checking a data value, the code does NOT belong in the load event of the form. The process will normally belong in the form's Current event ONLY.

It is very important to understand the form's event model so you know where to put your code. The events are not random. There is always a best or at least preferred home for all your code.

The Load event runs ONCE when the form opens and never again but the Current event runs once each time the form moves to a different (or new) record. So, as the data changes because the record changed, your code runs again:)
 

Users who are viewing this thread

Top Bottom