p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access VBA (http://p2p.wrox.com/forumdisplay.php?f=80)
-   -   Help! combo box results (http://p2p.wrox.com/showthread.php?t=38031)

dstein4d February 4th, 2006 07:40 PM

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?

mmcdonal February 6th, 2006 09:13 AM

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.



All times are GMT -4. The time now is 07:11 PM.

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