Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2004, 09:48 AM
Authorized User
 
Join Date: Aug 2003
Location: Austin, TX, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Want Combo Box first item if only 1 item

Assume an Access form with two combo boxes, ComboBox2 is based on a query. When the user makes a choice in ComboBox1, the choices in ComboBox2 are updated by ComboBox1's After Update Event Procedure of: Me.ComboBox2.Requery.

If, upon requery, ComboBox2 only has one item, I want ComboBox2 to show that item so the user doesn't have to click its drop down arrow and choose the item.

Thank you for your help!

Mark J. Weisberger
__________________
Mark J. Weisberger
Reply With Quote
  #2 (permalink)  
Old June 9th, 2004, 11:46 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the AfterUpdate event code try a variation of this:

strSQL = "SELECT criteria " similar to the criteria used in the rowsource in combo2
set rs = currentdb.openrecordset(strSQL)
rs.movelast
If rs.recordcount = 1 then
   Me.combo2 = "the matching field"
else
   Me.combo2 = null
end if
Me.combo2.requery

Cheers Ray
Reply With Quote
  #3 (permalink)  
Old June 9th, 2004, 12:42 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Simple enough... after the second combobox requeries, add this to its AfterUpdate event:

Code:
If Me.ComboBox2.ListCount = 1 Then
   Me.ComboBox2 = Me.ComboBox2.Column(0,0)
End If


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #4 (permalink)  
Old June 9th, 2004, 04:03 PM
Authorized User
 
Join Date: Aug 2003
Location: Austin, TX, USA.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Ray and Greg for your help. I used Greg's solution because it was more concise. Thanks again.

Mark J. Weisberger
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Item in a Binded Combo Box prasanta2expert C# 2 April 21st, 2008 08:45 AM
pre-selecting an item in a combo box kscase Visual Basic 2005 Basics 1 July 12th, 2007 07:33 AM
Combo Box item from SQLDataadpter... to Datagrid venkikrao VB.NET 0 April 19th, 2006 08:57 PM
How to Update Selected Item in Combo after Postbac ZArrinPour ASP.NET 1.0 and 1.1 Basics 2 February 21st, 2006 02:17 AM
Find Out First Item of each item Group Jane SQL Language 1 November 22nd, 2003 12:42 PM



All times are GMT -4. The time now is 07:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.