Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi, Everyone! Have a little issue on a form (in datasheet view) that has 4 different bonus checkboxes fields (holiday, 10 perc, 5 perc, no bonus) but when I use the ".enabled" property to make one or more available depending what the user clicks on, all specified checkbox from all records in the form get the action. I will like that only the current record (checkboxes) which the user is editing to perform the required action instead of all records in the form. Please see below code:

    Private Sub HolidayBonus_Click()

    If (Me.HolidayBonus) = -1 Then
    Me.Completion10.Enabled = True
    Me.Completion5.Enabled = False
    Me.NoBonus.Enabled = False
    Else
    Me.Completion10.Enabled = True
    Me.Completion5.Enabled = True
    Me.NoBonus.Enabled = True
    End If

    End Sub

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Unfortunately, when you work with a continuous form or a form in datasheet view, that is the way forms work. The only suggestion I can give you is to switch to a single record view where you only see one record at a time. The reason datasheet view and continuous forms work that way is because there is no mechanism to refer to a specific record in a form design.
    Wendell

  3. #3
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could use the OnCurrent Event to reset the enabled properties when the user changes record.
    That way changes to one record would not effect all.
    Andrew

  4. #4
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AKW View Post
    You could use the OnCurrent Event to reset the enabled properties when the user changes record.
    That way changes to one record would not effect all.
    Thanks guys! AKW the OnCurrent event with some extra if statements for every checkbox in the form, made it work just like I wanted it. see below:

    Private Sub Completion10_Click()

    If Me.Completion5 Or Me.NoBonus = -1 Then
    MsgBox "Please de-select any previous choices to continue"
    Me.Completion10 = 0
    Me.ContractTerm.SetFocus
    ElseIf Me.Completion5 Or Me.NoBonus = 0 Then
    Me.Completion5.Enabled = False
    Me.NoBonus.Enabled = False
    End If

    End Sub

    Private Sub Form_Current()

    Me.Completion10.Enabled = True
    Me.Completion5.Enabled = True
    Me.HolidayBonus.Enabled = True
    Me.NoBonus.Enabled = True

    End Sub

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Are you sure that works?

    As a rule, you need to repeat in the OnCurrent event the code that runs in the AfterUpdate events for any controls that effect things that are relevant.

    PS In your fitst post, you had
    Code:
    Me.Completion10.Enabled = True
    in both legs of the If then else statement.
    That looks like an error, but...
    Regards
    John



  6. #6
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by John Hutchison View Post
    Are you sure that works?

    As a rule, you need to repeat in the OnCurrent event the code that runs in the AfterUpdate events for any controls that effect things that are relevant.

    PS In your fitst post, you had
    Code:
    Me.Completion10.Enabled = True
    in both legs of the If then else statement.
    That looks like an error, but...
    John-Currently, I have a form in datasheet view with 4 checkboxes per record. Below is the code that I'm using to allow the users to only be able to select the checkbox accordantly:

    Private Sub Completion5_Click()

    If Me.Completion10 Or Me.NoBonus Or Me.HolidayBonus = -1 Then
    MsgBox "Please de-select any previous choices to continue"
    Me.Completion5 = 0
    Me.ContractTerm.SetFocus
    ElseIf Me.Completion10 Or Me.NoBonus Or Me.HolidayBonus = 0 Then
    Me.Completion10.Enabled = False
    Me.HolidayBonus.Enabled = False
    Me.NoBonus.Enabled = False
    End If

    End Sub

    Private Sub Completion10_Click()

    If Me.Completion5 Or Me.NoBonus = -1 Then
    MsgBox "Please de-select any previous choices to continue"
    Me.Completion10 = 0
    Me.ContractTerm.SetFocus
    ElseIf Me.Completion5 Or Me.NoBonus = 0 Then
    Me.Completion5.Enabled = False
    Me.NoBonus.Enabled = False
    End If

    End Sub

    Private Sub HolidayBonus_Click()

    If Me.Completion5 Or Me.NoBonus = -1 Then
    MsgBox "Please de-select any previous choices to continue"
    Me.HolidayBonus = 0
    Me.ContractTerm.SetFocus
    ElseIf Me.Completion5 Or Me.NoBonus = 0 Then
    Me.Completion5.Enabled = False
    Me.NoBonus.Enabled = False
    End If

    End Sub

    Private Sub NoBonus_Click()

    If Me.Completion5 Or Me.Completion10 Or Me.HolidayBonus = -1 Then
    MsgBox "Please de-select any previous choices to continue"
    Me.NoBonus = 0
    Me.ContractTerm.SetFocus
    ElseIf Me.Completion5 Or Me.Completion10 Or Me.HolidayBonus = 0 Then
    Me.Completion5.Enabled = False
    Me.HolidayBonus.Enabled = False
    Me.Completion10.Enabled = False
    End If

    End Sub

    Private Sub Form_Current()

    Me.Completion10.Enabled = True
    Me.Completion5.Enabled = True
    Me.HolidayBonus.Enabled = True
    Me.NoBonus.Enabled = True

    End Sub

  7. #7
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    What matters is that it works for you, but I don't follow the logic.

    If you set them all to true in the oncurrent event, doesn't that defeat the purpose? Remember the job of the oncurrent event is to set the properties correctly when you revisit an existing record, not just when you go to a new one.

    A line like this does not do what I think you intend.
    Code:
    If Me.Completion10 Or Me.NoBonus Or Me.HolidayBonus = -1 Then
    I think you mean

    Code:
    If (Me.Completion10= -1) Or (Me.NoBonus= -1) Or (Me.HolidayBonus = -1) Then
    If people can only chose one option out of 4, having 4 fields each with a checkbox is not the way to go. Have one field that takes one of 4 possible values (or null) is a better option.
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •