Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Automatically going to a row in a combobox.

Discussion in 'Information Technology' started by Bob, Nov 10, 2005.

  1. Bob

    Bob
    Expand Collapse
    Guest

    If I create a new record in my form, I want to go to the row that was last
    used during this session in the combobox.
    I know the value of the column(0) of the combobox that was last used. I need
    the bit of code that lets me go to the row
    that contains a particular value in column(0) of the combobox and display
    it.

    My code looks something like this

    Dim lastRowPrimaryKeyFieldValue As Long

    Private Sub combobox1_Change()
    If Me.NewRecord Then
    lastRowPrimaryKeyFieldValue = combobox1.Column(0)
    End If
    End Sub


    Private Sub combobox1_Enter()
    combobox1.Requery 'Because if another user changed the table for the
    combox we want to be sure
    'to have all possible selections
    available.
    'if we're on a new record we want to go back to the record that has
    lastRowPrimaryKey in column(0), if there
    'was one selected once previously, otherwise just dispay the combox the
    usual way.
    If Me.NewRecord And lastRowPrimaryKeyFieldValue <> 0 Then
    'This is what I need to know how to do. How do I display the row
    in the combox that has
    'the value of lastRowPrimaryKeyFieldValue in column(0)
    'Can anyone help?
    else
    'Form just displays the combobox in the usual way
    End If
    End Sub


    Any help would be greatly appreciated,

    Bob
     
  2. Loading...

    Similar Threads Forum Date
    So Nervous! - Going To Gurdwara For The First Time! Blogs Oct 16, 2016
    Sikh News Sikh Seva Volunteers Keep The Food Service Drive For The Needy Going After Passing Away Of Breaking News Jul 29, 2016
    Sikh Education Video For Kids - Charlie And Blue - Going To Gurdwara - YouTube Gurmat Vichaar Apr 23, 2016
    Leisure Going Back To India :) Business, Lifestyle & Leisure Apr 13, 2014
    Controversial Going Backward Hard Talk Mar 20, 2014

  3. Brendan Reynolds

    Brendan Reynolds
    Expand Collapse
    Guest

    Just set the DefaultValue property in the AfterUpdate event procedure ...

    Private Sub cboTest_AfterUpdate()

    Me.cboTest.DefaultValue = """" & Me.cboTest & """"

    End Sub

    --
    Brendan Reynolds


    "Bob" <bdufour@sgiims.com> wrote in message
    news:OUra96T5FHA.692@TK2MSFTNGP11.phx.gbl...
    > If I create a new record in my form, I want to go to the row that was last
    > used during this session in the combobox.
    > I know the value of the column(0) of the combobox that was last used. I
    > need the bit of code that lets me go to the row
    > that contains a particular value in column(0) of the combobox and display
    > it.
    >
    > My code looks something like this
    >
    > Dim lastRowPrimaryKeyFieldValue As Long
    >
    > Private Sub combobox1_Change()
    > If Me.NewRecord Then
    > lastRowPrimaryKeyFieldValue = combobox1.Column(0)
    > End If
    > End Sub
    >
    >
    > Private Sub combobox1_Enter()
    > combobox1.Requery 'Because if another user changed the table for the
    > combox we want to be sure
    > 'to have all possible selections
    > available.
    > 'if we're on a new record we want to go back to the record that has
    > lastRowPrimaryKey in column(0), if there
    > 'was one selected once previously, otherwise just dispay the combox the
    > usual way.
    > If Me.NewRecord And lastRowPrimaryKeyFieldValue <> 0 Then
    > 'This is what I need to know how to do. How do I display the
    > row in the combox that has
    > 'the value of lastRowPrimaryKeyFieldValue in column(0)
    > 'Can anyone help?
    > else
    > 'Form just displays the combobox in the usual way
    > End If
    > End Sub
    >
    >
    > Any help would be greatly appreciated,
    >
    > Bob
    >
     
  4. Bob

    Bob
    Expand Collapse
    Guest

    Thanks
    "Brendan Reynolds" <brenreyn@discussions.microsoft.com> wrote in message
    news:ufG%23h9W5FHA.3976@TK2MSFTNGP15.phx.gbl...
    > Just set the DefaultValue property in the AfterUpdate event procedure ...
    >
    > Private Sub cboTest_AfterUpdate()
    >
    > Me.cboTest.DefaultValue = """" & Me.cboTest & """"
    >
    > End Sub
    >
    > --
    > Brendan Reynolds
    >
    >
    > "Bob" <bdufour@sgiims.com> wrote in message
    > news:OUra96T5FHA.692@TK2MSFTNGP11.phx.gbl...
    >> If I create a new record in my form, I want to go to the row that was
    >> last used during this session in the combobox.
    >> I know the value of the column(0) of the combobox that was last used. I
    >> need the bit of code that lets me go to the row
    >> that contains a particular value in column(0) of the combobox and display
    >> it.
    >>
    >> My code looks something like this
    >>
    >> Dim lastRowPrimaryKeyFieldValue As Long
    >>
    >> Private Sub combobox1_Change()
    >> If Me.NewRecord Then
    >> lastRowPrimaryKeyFieldValue = combobox1.Column(0)
    >> End If
    >> End Sub
    >>
    >>
    >> Private Sub combobox1_Enter()
    >> combobox1.Requery 'Because if another user changed the table for the
    >> combox we want to be sure
    >> 'to have all possible selections
    >> available.
    >> 'if we're on a new record we want to go back to the record that has
    >> lastRowPrimaryKey in column(0), if there
    >> 'was one selected once previously, otherwise just dispay the combox
    >> the usual way.
    >> If Me.NewRecord And lastRowPrimaryKeyFieldValue <> 0 Then
    >> 'This is what I need to know how to do. How do I display the
    >> row in the combox that has
    >> 'the value of lastRowPrimaryKeyFieldValue in column(0)
    >> 'Can anyone help?
    >> else
    >> 'Form just displays the combobox in the usual way
    >> End If
    >> End Sub
    >>
    >>
    >> Any help would be greatly appreciated,
    >>
    >> Bob
    >>

    >
    >
     

Share This Page