Automatically going to a row in a combobox.

B

Bob

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
 
B

Brendan Reynolds

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

Private Sub cboTest_AfterUpdate()

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

End Sub
 
B

Bob

Thanks
Brendan Reynolds said:
Just set the DefaultValue property in the AfterUpdate event procedure ...

Private Sub cboTest_AfterUpdate()

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

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top