Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Setting Form to Selected Record (A97 SR01 under W98)

    I have a combo box in the header of a form, and the default selection in the combo box is the first record in the selection.

    How do I force the detail part of the form to the selection in the combo box upon opening the form? Right now I have to click in the combo box to go to the record.

    I should mention that the combo box selection is in alphabetical order whereas the records are not. Thus, upon openng the form the combo box comes up wth one selection and the detail section with another -- until I click on the selection in the combo box.

  2. #2
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Setting Form to Selected Record (A97 SR01 under W98)

    Thanks Hans,

    I do have an After Update routine as well as as an OnOpen event that sets the focus on the combo box and causes it to display the first record.

    However, something doesn't work. With the On Load routine looking like this

    Private Sub Form_Load()
    cboSelectActivity
    End Sub

    I get an "Invalid use of Property" compile error. The "cboSelectActivity" is simply the name of my combo box. I don't see how this can be executable code.

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Form to Selected Record (A97 SR01 under W98)

    Hi Chuck,

    Use :
    Private Sub Form_Load()
    cboSelectActivity_AfterUpdate
    End Sub
    Francois

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting Form to Selected Record (A97 SR01 under W98)

    Sorry, there was a typo in my previous post, so it's not your fault that it didn't work.

    You need to call the AfterUpdate routine of the combo box. You do this by appending an underscore _ and AfterUpdate to the name of the combo box:

    cboSelectActivity_AfterUpdate

    I hope it'll work now.

    Regards,
    Hans

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting Form to Selected Record (A97 SR01 under W98)

    <P ID="edit" class=small>Edited by HansV on 17-Apr-02 17:22.</P>I presume you have an AfterUpdate routine for the combo box. At the moment, you call this routine manually by clicking the combo box. You can do it automatically by calling this routine in the OnLoad event of the form.

    Example: if your combo box is called cboSelect, the AfterUpdate routine looks like this

    Private Sub cboSelect_AfterUpdate()
    ' Your code goes here
    End Sub

    Add the following line to the OnLoad event handler:

    cbo_AfterUpdate

    so it will look like

    Private Sub Form_Load()
    ' Other code goes here
    cbo_AfterUpdate
    End Sub

    Added later: there is a typo here. Sorry about that. Please see the following posts - HansV

  6. #6
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Setting Form to Selected Record (A97 SR01 under W98)

    Thanks everyone. I added your suggested code to my On Open routines like this:


    Private Sub Form_Open(Cancel As Integer)
    Me!cboSelectActivity.SetFocus
    Me!cboSelectActivity = Me!cboSelectActivity.ItemData(0)
    cboSelectActivity_AfterUpdate
    End Sub

    The cbo is in the header, so I had to add the first two lines to get the focus on the cbo and display the first record in it. Your suggestion then forces the detail section of the code to the record being displayed in the cbo. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •