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 VBA
Password Reminder
| FAQ | Members List | Calendar | 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 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?

Reply With Quote
  #2 (permalink)  
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.


Reply With Quote

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
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

All times are GMT -4. The time now is 05:20 AM.

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