Results 1 to 4 of 4
  1. #1
    bxdobs is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    35

    call to acCmdSelectRecord on form startup not working

    Using a Query/Datasheet subform on a Main Form app where the subform is in control



    The application works well once it is running ... however ... I haven't found an event that I can call:
    Code:
     Application.RunCommand acCmdSelectRecord
    to select the first record on the query subform
    when the Application starts

    This behaves like a cart before the horse issue ... when the app starts, even though subform events run
    first, Access hasn't actually given focus or drawn the subform ... I expect that acCmdSelectRecord requires
    the object it is intended to paint to already exist on the screen ... I haven't been able to find an event that
    fires after the initial application is drawn ... I could possibly add a one shot timer that would trap all user
    input until it times out ... this would also call the acCmdSelectRecord ... however ....
    was hoping someone would have a simpler solution

    Details

    Access runs all the subform events first before calling the Main Form Events

    Query subForm Open
    Query subForm Load
    Query subForm Current ' Calls subRecordSelect

    Main Form Current ' passes focus to the subForm
    Main Form subForm frmQuery_Enter

    I have a sub on the Query subForm that does the Record Select

    Code:
    Sub subRecordSelect(ByVal chSel As String)
    On Error GoTo endSelect
      Call dbg("Query subRecordSelect --- " & chSel)
      Application.RunCommand acCmdSelectRecord ' select entire record row
    endSelect:
    End Sub
    I just expected to call subRecordSelect directly from the last event fired to get the record to select ... I tried adding it to Form Current and Query_enter but this doesn't do anything ... the first record is selected but only the first field is highlighted instead of the entire row.

    Once the application is running the events fire in the following order for each key or mouse click (mouse and keydown events all flow through fnKeydown)

    Query fnKeyDown
    Query subRecordSelect ' updates the record selection

    Main Form subKeyin ' this is also a mouse / key click trap
    Main Form subUpdateScreen ' expands details on the main form about the query record


    Navigation:

    left and right arrows trigger a spin button which changes the Month Year of the Query
    up and down arrows trigger record scrolling on the subform

    all movement updates further related details of the current record on the main form

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    bxdobs -

    Don't know if this will help in your particular situation but, you could try something like:

    dim strSubformControl as String
    strSubformControl = "NAME OF YOUR SUBFORM"
    DoCmd.GoToControl strSubformControl
    DoCmd.GoToRecord acActiveDataObject,, acFirst
    DoCmd.RunCommand acCmdSelectRecord

    in the open event of the main form after any other processing.

    Hope this helps,

    Jim

  3. #3
    bxdobs is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    35
    I will try your recomendation shortly ...

    The one shot timer solution wasn't too bad ... this allows the Form to be completely drawn before applying the record select command

    Only had to filter the Spin Control as it was acting as if it had been spun when the control was enabled

    Code:
    Private Sub Form_Current()
       Me.TimerInterval = 100
    End Sub
    
    Private Sub Form_Timer()
       
       Call dbg("Query Timer")
       
       Me.TimerInterval = 0
       
       Call Me.Parent.subEnableControls
       Call subRecordSelect("Timer")
       
    End Sub

  4. #4
    bxdobs is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2012
    Posts
    35
    No, sorry, your suggested solution doesn't work in the the FORM_OPEN Main Form Event ... I expect this is still the same issue ... Access hasn't actually drawn the objects while its executing LOAD, Current or Open ... which again falls back to my first observation that this record selector command needs to have a physical GDI object in order for it to function.

    I think I will stick with the bandaid approach for now (using timer as a bandaid)

    In this case at least I know its a bandaid and I can describe how it works ... finding a real solution appears to be like looking for the holy grail ... would probably require digging in to the Windows API messaging to trap raw messages not being used as events in Access. The message I expect would have something to do with the window GDI object draw completed. Once the Access app has a GDI pointer to the form, it can then use custom paint requests like the acCmdSelectRecord

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

Similar Threads

  1. Odd problem with startup form
    By FTAUSS in forum Forms
    Replies: 2
    Last Post: 02-07-2012, 02:36 PM
  2. Default form view on startup
    By akhlaq768 in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 09:24 AM
  3. Buttons activating on form startup
    By howieyo in forum Forms
    Replies: 0
    Last Post: 06-13-2011, 06:48 PM
  4. Stop Form Jumping on Startup
    By mapline in forum Programming
    Replies: 9
    Last Post: 05-21-2011, 08:31 PM
  5. Startup form not showing?
    By cfasoftware in forum Access
    Replies: 1
    Last Post: 01-21-2010, 03:10 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