none
Locking Controls from 90 days old! RRS feed

  • Question

  • The first code is on opening of my form, I am trying to lock some controls after 90 days and leave some enable, This code I thought would do this but its not, any help please............Regards Bob

    bLockFlag = False

      Dim dDate As Date
                Dim dtDiff
                Dim nCountDaysOfYear As Long
                Dim nLeapYearNow As Long, nLeapYearOfBillYear As Long
                Dim nTotalDays As Long
                dDate = Form_frmModify.lstModify.Column(3)
              
                dtDiff = DateDiff("d", dDate, Date)
              
                nLeapYearOfBillYear = DatePart("yyyy", dDate)
                nLeapYearOfBillYear = nLeapYearOfBillYear Mod 4
             
                nLeapYearNow = DatePart("yyyy", Date)
                nLeapYearNow = nLeapYearNow Mod 4
               
                If nLeapYearNow = 0 Or nLeapYearOfBillYear = 0 Then
                    nTotalDays = 90
                Else
                    nTotalDays = 90
                End If
               
                If dtDiff > nTotalDays Then
                    cmdClose.SetFocus
                    subLockControls False, True
                    bLockFlag = True
                Else
                    subLockControls True, False
                End If
                    Exit Sub
                End If
    ========================================================

    Public Sub subLockControls(bFlagEnabled As Boolean, bFlagLocked As Boolean)


    cmdDelete.Enabled = bFlagEnabled

    Form_subAdditionCharge.tbAdditionCharge.Locked = bFlagLocked
    Form_subAdditionCharge.tbAdditionChargeAmount.Locked = bFlagLocked
    Form_subAdditionCharge.tbDayNo.Locked = bFlagLocked
    Form_subAdditionCharge.cbChargeID.Locked = bFlagLocked
    Form_subAdditionCharge.tbChargeNumber.Locked = bFlagLocked
    Form_subAdditionCharge.cmdDelete.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdDeleteDate.Enabled = bFlagEnabled
    cmdClose.Enabled = True
    End Sub


    xxx

    Sunday, August 16, 2015 1:02 AM

Answers

  • Hi TurnipOrange,

    >> I am trying to lock some controls after 90 days and leave some enable, This code I thought would do this but its not

    Which situation your code did not work, some controls did not lock or some control did not enable? I made a simple test with your code, it worked correctly to enable or unable the control.

    Private Sub Form_Current()
                Dim bLockFlag As Boolean
                bLockFlag = False
                Dim dDate As Date
                Dim nDiff As Long
                 Dim nCountDaysOfYear As Long
                 Dim nTotalDays As Long
                 'dDate = "2015/8/15" 'Form_frmModify.lstModify.Column(3)
                 dDate = "2015/3/15" 'Form_frmModify.lstModify.Column(3)
                 Debug.Print Date
                 nDiff = DateDiff("d", dDate, Date)
    
                 nTotalDays = 90
    
                 If nDiff > nTotalDays Then
    '                 cmdClose.SetFocus
                     subLockControls False, True
                     bLockFlag = True
                 Else
                     subLockControls True, False
                 End If
    End Sub
    Public Sub subLockControls(bFlagEnabled As Boolean, bFlagLocked As Boolean)
    Form_tblInkEdit.ActiveXCtl1.Enabled = bFlagEnabled ‘ this is control I have
    ' Form_subAdditionCharge.tbAdditionCharge.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbAdditionChargeAmount.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbDayNo.Locked = bFlagLocked
    ' Form_subAdditionCharge.cbChargeID.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbChargeNumber.Locked = bFlagLocked
    ' Form_subAdditionCharge.cmdDelete.Enabled = bFlagEnabled
    ' Form_subAdditionCharge.cmdDeleteDate.Enabled = bFlagEnabled
    ' cmdClose.Enabled = True
     End Sub

    For your issue, I suggest you check the value of the “nDiff”, and as the reply from Tom, debug your code step by step to check where the code did not work.

    Best Regards,

    Edward

                            

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by TurnipOrange Monday, August 17, 2015 10:53 PM
    Monday, August 17, 2015 5:43 AM

All replies

  • Is this a form with DefaultView property set to Single View?
    If so, you need to move this code to Form_Current.

    To simplify the problem, comment out all the code about leap years. More about that later if you wish, but it is not central to your issue.

    Rewrite this line:
    Dim dtDiff

    to:
    Dim nDiff as Long
    and fix up the ripple effect.

    Then set a breakpoint on the first line, and step through carefully, inspecting variables as you go along. You will find out what's wrong.


    -Tom. Microsoft Access MVP

    Sunday, August 16, 2015 1:17 AM
  • Thanks Tom, Yes it is single form with a sub form. I don't really need the leap year option. I do have the code:

    Public Sub subLockControls(bFlagEnabled As Boolean, bFlagLocked As Boolean) In Current

    Altered my code in Open form:

     Dim dDate As Date
             Dim nDiff As Long
                Dim nCountDaysOfYear As Long
                'Dim nLeapYearNow As Long, nLeapYearOfBillYear As Long
                Dim nTotalDays As Long
                dDate = Form_frmModify.lstModify.Column(3)
              
                nDiff = DateDiff("d", dDate, Date)
              
                'nLeapYearOfBillYear = DatePart("yyyy", dDate)
                'nLeapYearOfBillYear = nLeapYearOfBillYear Mod 4
             
               ' nLeapYearNow = DatePart("yyyy", Date)
               ' nLeapYearNow = nLeapYearNow Mod 4
               
               ' If nLeapYearNow = 0 Or nLeapYearOfBillYear = 0 Then
                    nTotalDays = 90
                Else
                    nTotalDays = 90
                End If
               
                If nDiff > nTotalDays Then
                    cmdClose.SetFocus
                    subLockControls False, True
                    bLockFlag = True
                Else
                    subLockControls True, False
                End If
                    Exit Sub

    Does this look ok? Thanks Bob


    xxx

    Sunday, August 16, 2015 1:32 AM
  • Slight change to code?

      bLockFlag = False

                     Dim dDate As Date
             Dim nDiff As Long
                Dim nCountDaysOfYear As Long
             
                Dim nTotalDays As Long
                dDate = Form_frmModify.lstModify.Column(3)
              
                nDiff = DateDiff("d", dDate, Date)
              
              
                    nTotalDays = 90
             
               
                If nDiff > nTotalDays Then
                    cmdClose.SetFocus
                    subLockControls False, True
                    bLockFlag = True
                Else
                    subLockControls True, False
                End If


    xxx

    Sunday, August 16, 2015 2:41 AM
  • Hi TurnipOrange,

    >> I am trying to lock some controls after 90 days and leave some enable, This code I thought would do this but its not

    Which situation your code did not work, some controls did not lock or some control did not enable? I made a simple test with your code, it worked correctly to enable or unable the control.

    Private Sub Form_Current()
                Dim bLockFlag As Boolean
                bLockFlag = False
                Dim dDate As Date
                Dim nDiff As Long
                 Dim nCountDaysOfYear As Long
                 Dim nTotalDays As Long
                 'dDate = "2015/8/15" 'Form_frmModify.lstModify.Column(3)
                 dDate = "2015/3/15" 'Form_frmModify.lstModify.Column(3)
                 Debug.Print Date
                 nDiff = DateDiff("d", dDate, Date)
    
                 nTotalDays = 90
    
                 If nDiff > nTotalDays Then
    '                 cmdClose.SetFocus
                     subLockControls False, True
                     bLockFlag = True
                 Else
                     subLockControls True, False
                 End If
    End Sub
    Public Sub subLockControls(bFlagEnabled As Boolean, bFlagLocked As Boolean)
    Form_tblInkEdit.ActiveXCtl1.Enabled = bFlagEnabled ‘ this is control I have
    ' Form_subAdditionCharge.tbAdditionCharge.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbAdditionChargeAmount.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbDayNo.Locked = bFlagLocked
    ' Form_subAdditionCharge.cbChargeID.Locked = bFlagLocked
    ' Form_subAdditionCharge.tbChargeNumber.Locked = bFlagLocked
    ' Form_subAdditionCharge.cmdDelete.Enabled = bFlagEnabled
    ' Form_subAdditionCharge.cmdDeleteDate.Enabled = bFlagEnabled
    ' cmdClose.Enabled = True
     End Sub

    For your issue, I suggest you check the value of the “nDiff”, and as the reply from Tom, debug your code step by step to check where the code did not work.

    Best Regards,

    Edward

                            

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by TurnipOrange Monday, August 17, 2015 10:53 PM
    Monday, August 17, 2015 5:43 AM
  • Thanks Tom and Edward, Got it going great. Didn't have the code in current!

    When I am locking [tbStartDate1] if it is 3 months old Invoice and I want say [tbStartDate2] not to lock, I don't have to code that textbox because it will be unlocked anyway?

    tbStartDate1.Enabled = bFlagEnabled

    Thanks for your help.....Bob


    xxx

    Monday, August 17, 2015 10:57 PM
  • Interesting, Wont let me lock a combo box with a value list! Regards Bob

    xxx

    Tuesday, August 18, 2015 8:31 AM
  • Hi TurnipOrange,

    I made a test with a combo box with an entered value list, it was disabled correctly with the code below

    Private Sub Form_Current()
    Form_tblInkEdit.Combo16.Enabled = False
    End Sub

    I assume that it may be related with “if statement” in your code, and suggest you debug your code step by step.
    Since your original issue has been resolved, and if you still have issues about locking a combo box, I suggest you post a new thread for this specific issue, and then we could focus on this, and there would be more community members to help you.

    In addition, in your new post, it would be helpful if you could share us your code and steps to reproduce your issue.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, August 19, 2015 1:54 AM
  • Thanks Edward, it seems to be only locking the combo box in the new record not the old records. Regards Bob

    All other codes are locking controls!

    Form_subAdditionCharge.cmdDelete.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdDeleteDate.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdAdd100.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdPlus50ChargeAmount.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdPlus20ChargeAmount.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdPlus10ChargeAmount.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdPlus5ChargeAmount.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdZero.Enabled = bFlagEnabled
    Form_subAdditionCharge.tbAdditionCharge.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdEnterStandard.Enabled = bFlagEnabled
    Form_subAdditionCharge.cbChargeID.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdOneDayBack.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmdOneDayFoward.Enabled = bFlagEnabled
    Form_subAdditionCharge.tbAdditionChargeAmount.Enabled = bFlagEnabled
    Form_subAdditionCharge.tbDayNo.Enabled = bFlagEnabled
    Form_subAdditionCharge.cmbTimesAmount.Enabled = bFlagEnabled ' this combo box


    xxx

    Wednesday, August 19, 2015 11:13 PM
  • Hi TurnipOrange,

    I made a test with new and old records, but all are ok at my side. First of all, I suggest you just use the code below in a command button to check whether it works or not.

    Private Sub DisableBtn_Click()
    Form_tblInkEdit.Combo16.Enabled = False
    MsgBox Form_tblInkEdit.Combo16.Enabled
    End Sub

    Second, after you set it as disabled and before you check the result of it, I suggest you in a button to check the result of the code below:

    MsgBox Form_tblInkEdit.Combo16.Enabled

    If it is true, I assume there is some other code enable it. And I suggest you check all of the related code.

    Anyway, I suggest you post a new thread for this, and share us steps to reproduce your issue. Then more community members could know your current issue, and could help you. You could post the new thread link here, and we will keep following in the new thread.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, August 20, 2015 1:48 AM