Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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
Old February 4th, 2006, 07:40 PM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help! combo box results

I want to be able to select from my combo box an item to add to my search criteria. How can I take the selection in the combo box and assign it to a string so I can add it to my SQL statement?

Old February 6th, 2006, 09:13 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

It depends. Generally the combo box will take the PK of the record you are searching for in the combo box. This can be problematic if you are limited to unique values and you only want to return one record.

You can either pass the PK of the record found in the combo box, the value appearing in the combo box, or any of the values in any of the columns in your look up query.

You can also have the query that your form or report is built on look for the combo box on the form you are searching from by adding a statement to the query iteself like this:


  So when the query opens, it will just look for whatever is in your combo box at the time, no need to pass the value in a SQL statement.

Here is how you pass an integer:

Dim inComboValue As Integer
Dim stLink As String

inComboValue = Me.MyComboBox

stLink = "[MyIntegerField] = " & inComboValue

Here is how you pass a string:

Dim stComboValue As String
Dim stLink As String

stComboValue = Me.MyComboBox

stLink = "[MyStringField] = " & "'" & stComboValue & "'"

  You may also wish to check for IsNull or "" in the combo box so that your code does not through an error if a user clicks the button without selecting a value.



Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM

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