Disable save button

ivonsurf123

Registered User.
Local time
Yesterday, 19:34
Joined
Dec 8, 2017
Messages
69
Hello,

I am trying to disable save button when the cboYear is not <> currentYear,
right now the code I have is disabling all the years including the current year when I filter the cboYear, Do I need to add this code somewhere else like on Load or Current? Or Am I missing something else? Please Help. Thank you.

Code:
Private Sub cboYear_AfterUpdate()

    Dim myDate
    
    myDate = Year(Date)
    
    If (Me.cboYear) <> myDate Then
        Me.cmdSave.Enabled = False
    Else
        Me.cmdSave.Enabled = True
    End If
    
    If IsNull(Me.cboYear) Then
        Me.subform_Register_PublicHolidays.Form.Filter = ""
        Me.subform_Register_PublicHolidays.Form.FilterOn = False
    Else
        Me.subform_Register_PublicHolidays.Form.Filter = "Year(PHDate)=" & Me.cboYear
        Me.subform_Register_PublicHolidays.Form.FilterOn = True
    End If


Proc_Exit:
   Exit Sub
Proc_Error:
   MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
   Resume Proc_Exit
End Sub
 
The logic looks correct... try being more explicit with types (you're leaving a lot up to interpretation by the compile/runtime):

Code:
Dim myDate [B]As Integer[/B]
MyDate = Year(Date)

If [B]CInt([/B]Me.cboYear[B].Value)[/B] <> MyDate Then
...

(if the combo is nullable, wrap that check in NZ() as well)
 
OMG! jleach that was beautiful CInt did it. Thank you so much!
 
Thank you Pat! I Will check my code and test it to follow your advised, I appreciate it.
 

Users who are viewing this thread

Back
Top Bottom