Results 1 to 7 of 7
  1. #1
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24

    Question Setfocus Split Form Issues

    I use the below code to filter and modify my form based on the selection in a combo box:

    If Me.CboShowMe = "Current Employees" Then
    DoCmd.ApplyFilter , "isNull(TerminationDate)"
    Screen.ActiveDatasheet.PostLocation.ColumnWidth = 0
    Screen.ActiveDatasheet.PostedDate.ColumnWidth = 0
    Screen.ActiveDatasheet.TerminationDate.ColumnWidth = 0
    Screen.ActiveDatasheet.Position.ColumnWidth = 0
    End If


    The problem is that I am unable to get this code to work in the On Load or On Open events (I want this above setting to be the default when the form opens). When I attempt to use this code in On Open or On Load I get errors with the Screen.ActiveDatasheet command. Any Ideas

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what is it that you want to do?

    if you want that on the LOAD event of the form, the first thing you can do is eliminate the conditional, because a form always loads a control value according to whatever is in that control's "default value" property. If nothing is in it, the control will pull the first record's value, or if it's an unbound form, the DEFAULT value listed in properties.

  3. #3
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    Hello Adam,

    The form is a split form. I had to add the Screen.ActiveDatasheet command in order to set focus on the table portion of the form. What I am trying to do now is hide and filter columns when the form is loaded. There are more selections that the user can make in the CboShowMe combo box; however, this is the setting I want the split form to default to.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    i do not use "screen.active" 'anything'. so, I can't really help with that.

    if I were doing it, I would change the sql rowsource of the sheet on the event I was working with. That way, there is only 2 lines of code that would be necessary:
    Code:
    me.sub.rowsource = sql
    me.sub.form.requery

  5. #5
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    I have to be honest, that went over my head

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by cksm4 View Post
    I have to be honest, that went over my head
    did you at least feel the breeze?

    okie dokie...a subform has 2 important props (properties): source object and rowsource. a subform is NOT a form control, it's an object in the db window somwhere. but in order for it to be embedded into another form (effectively making it a 'subform'), it has to reside inside a 'shell' control. the shell is just like any other control (tbox, combo, label, etc.) ... it has name, events, etc, etc...

    make sense so far?

    the biggest difference between a subform and other controls is that it has a complete set of 'extension properties'. what this means is that you can use (in code only) it's FORM properties however you want to.

    make sense so so far?

    so...click on the subform's SHELL and you'll see props like 'name', 'source object', etc... on the various tabs. click on the little square in the upper left corner (just like you would any main form) to get the props of its source object and you'll see the exact same props as you do for the main form.

    make sense so so so far?

    the 'record source' and 'source object' properties have absolutely nothing to do with each other. they are completely unrelated. you need an 'object source' for the subform to exist and be visible, you need a 'record source' to be available to display any data. and thus...

    if you use the code I posted 2 posts ago you should be able to use this explanation and that code to get done what you want to.

    make sense so so so so far?

    HTH!

    <edit>

    forgot to mention that I do believe the 'rs source' IS present in only one place... the 'source object'. Essentially what happens is if you change this prop while the 'source object' is open on the screen as a subform, or as an actual object (stand-alone), it is universally changed. hope that makes sense. if not, forget it - it's not really relevant to what you're doing.

  7. #7
    cksm4 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    24
    I think the error is related to the table portion of the split form (not subform). The code works when the form is loaded; however, I have to use the Screen.ActiveDatasheet command to set focus on the table portion of the split form in first.

    This code does not work from the On Load or On Open. I am thinking I am unable to set focus on the table for some reason as the error occurs at the first use of Screen.ActiveDatasheet.

    I even used the Call command to run the code that works, which still did not work. This is why I am thinking something different happens in the On Load or On Open that is preventing me from setting focus on the table section.

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

Similar Threads

  1. SetFocus/Require Entry
    By mbake085 in forum Programming
    Replies: 5
    Last Post: 08-19-2010, 07:32 AM
  2. Help with multiple form issues
    By AKQTS in forum Forms
    Replies: 0
    Last Post: 08-18-2010, 07:57 AM
  3. SetFocus Problem
    By ColPat in forum Programming
    Replies: 2
    Last Post: 06-21-2010, 04:43 AM
  4. Split Form Sync up
    By jonsuns7 in forum Forms
    Replies: 1
    Last Post: 11-10-2009, 02:56 PM
  5. SetFocus Issue
    By Sinjin in forum Access
    Replies: 0
    Last Post: 02-14-2008, 07:31 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