Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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
  #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
  #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


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.