Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2005

Tip: Looking for answers? Try searching our database.

Selecting a combo box item programatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ibrahim Mesbah - 17 Dec 2005 07:30 GMT
I implemented a wizard that dynamically updates the sub forms when Next is
clicked.  I would like to automatically select a certain item in a combo box
in one of the sub forms.  The combo box is filtered, so it only has one item.
Is there a way to select the first item programatically???  The subform is
in DataEntry mode.

I'd think there would be a property I could set, like SelectedIndex or
something, but there isn't.

Thanks in advance.
Brendan Reynolds - 17 Dec 2005 12:24 GMT
Me.Combo2 = Me.Combo2.ItemData(0)

Where 'Combo2' is the name of your combo box. The ItemData collection is
zero-based, so ItemData(0) is the first item in the list, ItemData(1) is the
second item, etc.

Signature

Brendan Reynolds

>I implemented a wizard that dynamically updates the sub forms when Next is
> clicked.  I would like to automatically select a certain item in a combo
[quoted text clipped - 8 lines]
>
> Thanks in advance.
Ibrahim Mesbah - 18 Dec 2005 00:26 GMT
Thank you.  That worked, but still having problems.  I was doing this logic
in the OnLoad function, and it didn't work.  I'm guessing it's because the
combo was yet to be calculated.  The row source for this combo is a sql
statement.  So I moved the code to the OnCurrent, and that seemed to work,
except now the focus is not at the first field.  I figured, ok, i'll just set
the focus to the first field, which is a requireed one, using SetFocus after
the combo box operation, but that didn't work.  When I click in the text box
manually, I get an error msg from Access saying the field cannot be null (the
first one).  I click on ok, then click in the field, and it's good.  I
figured I can get around this by turning the warnings off, but that didn't
help...  The more I use access the more I hate it - documentation sucks too..

Thanks again

> Me.Combo2 = Me.Combo2.ItemData(0)
>
[quoted text clipped - 14 lines]
> >
> > Thanks in advance.
John B - 29 Dec 2005 04:59 GMT
If you want to trigger AfterUpdate event, add:

Me.Combo2.Requery
after Me.Combo2 = Me.Combo2.ItemData(0)

> Me.Combo2 = Me.Combo2.ItemData(0)
>
[quoted text clipped - 14 lines]
> >
> > Thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.