Results 1 to 12 of 12
  1. #1
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21

    hide checkbox in a form

    Hi, i am trying to hide some labels and checkboxes in a split form



    through onClick, it works fine
    but when i tried to do the exact same thing in onCurrent, it made the checkboxes unclickable, but didn't hide them.

    would someone please help, thanks a lot

    Private Sub chk_be_replacement_Click()
    If Me.chk_be_replacement = True Then
    Me.internalLabel.Visible = True
    Me.internal_ind.Visible = True
    Else
    Me.internalLabel.Visible = False
    Me.internal_ind.Visible = False
    End If

    End Sub


    Private Sub Form_Current()
    Me.chk_be_replacement = False
    Me.internalLabel.Visible = False
    Me.internal_ind.Visible = False
    End Sub

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    You havene't actually used the same code on the OnCurrent.
    Why don't you try that as follows:

    Private Sub chk_be_replacement_Click()
    If Me.chk_be_replacement = True Then
    Me.internalLabel.Visible = True
    Me.internal_ind.Visible = True
    Else
    Me.internalLabel.Visible = False
    Me.internal_ind.Visible = False
    End If
    End Sub

    Private Sub Form_Current()
    If Me.chk_be_replacement = True Then
    Me.internalLabel.Visible = True
    Me.internal_ind.Visible = True
    Else
    Me.internalLabel.Visible = False
    Me.internal_ind.Visible = False
    End If
    End Sub

  3. #3
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    yes, i actually had tried that.
    somehow, .Visible = true/false doesn't work on onCurrent event.
    i have tried other things such as Enabled = true/false and it worked. it's not what exactly i need though.

    thanks,

  4. #4
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    There's no reason why the code won't work on the OnCurrent unless there is no value to test i.e if Me.chk_be_replacement is null.

    You caould add another line to your code to test for this as follows:

    Code:
     
    if not isnull(me!chk_be_replacement) then
     If Me.chk_be_replacement = True Then
      Me.internalLabel.Visible = True
      Me.internal_ind.Visible = True
     Else
      Me.internalLabel.Visible = False
      Me.internal_ind.Visible = False
     End If
    Else
     Me.internalLabel.Visible = False
     Me.internal_ind.Visible = False
    end if

  5. #5
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    i just tried what you suggested, but still no luck.
    i had problem with onCurrent before when i wanted to update rowSource of a listbox.
    i had it working by calling Requery after i assigned a new value to the rowSource while i didn't have to call Requery if i did it in a onClick function.

    so i guess there is something about onCurrent, particularly in Access 2007 perhaps?

  6. #6
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    so i guess there is something about onCurrent, particularly in Access 2007 perhaps?
    I don't think so.
    I use this kind of code all the time with no problems.
    If you post your database I can take a look if you want.

  7. #7
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    YES, that would be great, but how exactly do i post a DB on here?
    i have deleted other tables and minimized the DB size down to 600K.
    if you have a mailbox that i can send it to, i would love to do so.

    thanks for your help

  8. #8
    SteveF is offline Generally AccessAble
    Windows XP Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Location
    Fourth Corner
    Posts
    123
    PMFJI, but this probably has something to do with the order of events that happen when a form is opened. Also, the Current event of a form can be fired more than once, for example if the form is left open while another form or report is displayed -- when you return to the original form, Current is one of the events that fires upon the return.

    Whenever I encounter unwanted behavior with something I want to occur once when a form opens, I will often put the code for that in the form's Timer event, with a very short timer duration. This guarantees that my code will be the LAST thing that runs when the form loads, and the form is thus in a stable condition. Here's the equivalent code to your Current event moved to the Timer -- I would set the Timer Interval property of the form to a value of 100:

    Private Sub Form_Timer()

    Me.TimerInterval = 0 'run the timer event once; don't repeat this event

    Me.chk_be_replacement = False
    Me.internalLabel.Visible = False
    Me.internal_ind.Visible = False
    End Sub

    You can also change your check-box click event as follows -- move the code to the AfterUpdate event instead:

    Private Sub chk_be_replacement_AfterUpdate()
    Me.internalLabel.Visible = chk_be_replacement
    Me.internal_ind.Visible = chk_be_replacement
    End If

    Since the value of chk_be_replacement is either True or False, you can substitute a reference to the check box to supply the value for the Visible property of the other controls.

    Steve

  9. #9
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    You can send me a private message or email with the database attached

  10. #10
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    that's an interesting idea. reminds me how i handle ajax calls on JSP pages.
    i tried the timer, but still no luck
    the situation now is that
    when a checkbox is supposed to be hidden, it still shows but becomes not clickable.
    when a check is supposed to be disabled, it becomes not clickable but doesn't turn gray when you click on the very next record. then it will turn gray when you click the next one...

    SoftwareMatters,
    i have attached the DB, please take a look at you when you got a chance.
    ps: i commented out the code to set the fields invisible for now.

    thank you

  11. #11
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Hi,
    Because it is a split form you need to target the controls using the form name too as follows:

    Forms![Radio Family Form]!internal_ind.Visible = True

    So your code would become:

    Code:
    Private Sub chk_be_replacement_Click()
     Forms![Radio Family Form]!internalLabel.Visible = Forms![Radio Family Form]!chk_be_replacement
     Forms![Radio Family Form]!internal_ind.Visible = Forms![Radio Family Form]!chk_be_replacement
    End Sub
     
     
    Private Sub Form_Current()
     chk_be_replacement_Click()
    End Sub
    Note: The control 'chk_be_replacement' is unbound so you will need to add another yes/no field to your db and link it to this control. Then your oncurrent will work.

  12. #12
    hung_ko is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2010
    Posts
    21
    NICE! it works!
    i got to read more about the bound/unbound and form control on Access Forms.

    thank you so much for your help, SoftwareMatters

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

Similar Threads

  1. Form Checkbox/combobox help
    By KevinMCB in forum Forms
    Replies: 4
    Last Post: 11-30-2010, 11:05 AM
  2. Hide Duplicates In Look Up Form
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 09-30-2010, 12:23 PM
  3. Disable checkbox on a form
    By caffe in forum Forms
    Replies: 2
    Last Post: 09-16-2010, 07:37 AM
  4. Replies: 3
    Last Post: 08-13-2010, 11:23 PM
  5. Checkbox in continous form
    By senthilrg in forum Access
    Replies: 11
    Last Post: 12-05-2009, 08:49 AM

Tags for this Thread

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