Results 1 to 6 of 6
  1. #1
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41

    Show/Hide Form

    I am trying to setup a customized Time Entry system. Anything advanced that I've figured out how to do in Access over the last 10 or so years is self taught so I wonder at times if there's an easier/better way. Like now... I'll apologize in advance if I'm confusing or not giving the right info.



    I have two different time entry forms. One or the other of these forms should be visible or hidden on the main form (frmHRDB) depending on the value stored in the "TSType" field. I have code to set the 'visible' property of the two forms.

    My problem is that I've attached this code to several different controls on the form so that whenever a control is clicked or whatnot the form's visible property is correct regardless of which employee is showing. But as I add more controls I'm going to have to add this code again and again. I know this can't possibly be the correct/best way to do this.

    Can someone please give me some guidance on this? Thanks very much in Advance! I've attached a copy of my DB with one dummy record so my forms show up.
    Last edited by sparlaman; 05-16-2011 at 10:17 AM. Reason: left something out

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you mean the code behind btnEnterTime with

    If Me.txtTSType.Value = "Shop" Then

    I'd probably have a form-level public function that had that code, and in each of the events you would have had that code, just call the function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,043
    Hi,

    if the visible/invisibility depends on the content of 1 field, the code should only trigger from 2 events: the AfterUpdate from that field and the OnCurrent event from the form (gets triggered when moving focus to another record.

    You write the code once in a private sub like:
    ========================
    Private sub SetSubforms
    On error goto .............

    me.sfrNameSubform.visibible = (me.TSType= "Shop")
    me.sfrOtherSubform.visible = not(me.TSTType = "Shop")
    .........ect..........

    [error handling]
    End Sub
    ========================

    and then call that sub wherever needed:

    =====================
    Private Sub Form_Current()
    call SetSubforms
    End Sub
    ==================
    Private Sub txtTSType_AfterUpdate()
    call SetSubforms
    End Sub

    gr
    NG

  4. #4
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    I need to fiddle with this to see if I can make sense of it.

    Thanks very much!

    sparlaman
    Last edited by sparlaman; 05-16-2011 at 10:55 AM. Reason: I'm a moron

  5. #5
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    NG,

    So, where do I put the setSubforms sub? I am understanding the logic but not the execution of what you are telling me. Thanks

    (*sigh* I need to take a class on VBA or someting...)

  6. #6
    sparlaman is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    41
    Woohoo! OK, the On Current thing was the key. Thanks! I just was putting the code in the wrong form's On Current event. I kept trying to put it in the subform's event instead of the main form.

    I would still like to understand doing the public function & calling that function when I need it. I recognize that as the better way to code. So, if either of you would care to elaborate, I'm listening.

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

Similar Threads

  1. Hide Access and show only my forms
    By mortenskipper in forum Access
    Replies: 8
    Last Post: 01-20-2016, 08:21 AM
  2. Replies: 6
    Last Post: 02-24-2011, 03:24 PM
  3. Hide and show tekstbox
    By Patience in forum Access
    Replies: 3
    Last Post: 06-18-2010, 06:15 AM
  4. Show/Hide Columns in a Query
    By SCFM in forum Access
    Replies: 1
    Last Post: 02-23-2010, 08:04 AM
  5. Show Hide Subreport / acViewReport
    By BigBear in forum Reports
    Replies: 4
    Last Post: 03-30-2009, 06:07 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