Results 1 to 7 of 7
  1. #1
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209

    Problem with AfterClick()

    Here is what I be needing:


    I have a tickbox, and I am wanting it to disable the tickbox if you check it, but disable it after the "Add Record" button has been pressed. I set it up by uing the AfterUpdate feature of the tickbox, but it is locking as soon as I check the box, not once the "Add Record" button is pressed. The Visaul Basik code that I used was:

    Code:
     
    Private Sub Check146_AfterUpdate()
    If Me.Check146 = True Then
    Me.Check134.SetFocus
    Me.Check146.Enabled = False
    Me.Check144.Enabled = False
    Me.Check148.Enabled = False
    
    Else
    
    Me.Check144.Enabled = True
    Me.Check146.Enabled = True
    Me.Check148.Enabled = True
    
    End If
    End Sub
    I also tried to set it up on the AfterClick() on the "Add Record" button, but this wouldn't even allow the record to lock.

    I really want the code to read:
    Code:
    If Me.Check146 And Me.Check144 = True Then....
    But when I tried this code, the Debugger gave no error, but Access would not disable any fields at all?

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    I you want the code to only run once the "Add Record" button (i assume this meas save the record) is pressed then use the form's After Update event.

    Code:
    Private Sub Form_AfterUpdate()
    If Me.Check146 = True and Me.Check144 = True Then
    Me.Check134.SetFocus ' probably will not need this since the focus will be on your command button
    Me.Check146.Enabled = False
    Me.Check144.Enabled = False
    Me.Check148.Enabled = False
    
    Else
    
    Me.Check144.Enabled = True
    Me.Check146.Enabled = True
    Me.Check148.Enabled = True
    
    End If
    End Sub
    TIP: give your controls more meaningful names other than using just the default names.

  3. #3
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Additionally,

    When viewing current record and you want this some thing to happen then you will also need to need to use the form's On Current event.

    You might also consider locking the control not disabling it.

    You could also write your code like this:

    Code:
    Private Sub Form_AfterUpdate()
    
    Me.Check146.Enabled = Not (Me.Check146 = True and Me.Check144 = True)
    Me.Check144.Enabled = Not (Me.Check146 = True and Me.Check144 = True)
    Me.Check148.Enabled = Not (Me.Check146 = True and Me.Check144 = True)
    
    End Sub

  4. #4
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    I would using the tickbox for check146 AfterUpdate() not for the form, I will try to switch to the Form's AfterUpdate() event and see if that will fix the problem. I set the Check134.SetFocus because I would click check146 and it would tell me error something about the focus, but when I added the .SetFocus and moved the focus from the box I was clicking it was fixed.

    How do you knwo when you should used the Forms AfterClick() event or use the command buttons AfterClick() event?

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by Juan4412 View Post
    I set the Check134.SetFocus because I would click check146 and it would tell me error something about the focus, but when I added the .SetFocus and moved the focus from the box I was clicking it was fixed.
    That would be correct if the control you are trying to disable has the focus.

    What I am saying is that if you click a button to save the record the focus will have already changes. When the form's after update event fires it can disable the check box controls on the form since the save button still has the focus.


    Quote Originally Posted by Juan4412 View Post
    How do you knwo when you should used the Forms AfterClick() event or use the command buttons AfterClick() event?
    Control's event:
    If you want to do something after a control has been changed and before the record has been saved you would use the control's after update event.

    Form's event:
    If you want to do someting after the Form's changes have been saved you would use the Form's After Update Event.

    TIP:
    I use the Befeore Update events for validation. This way you can Cancel the event.

  6. #6
    Juan4412 is offline Competent Performer
    Windows 7 Access 2002
    Join Date
    Dec 2010
    Posts
    209
    Thank you for the help

  7. #7
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by Juan4412 View Post
    Thank you for the help
    You're welcome.

    Glad we could assist.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  2. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums