Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

Getting third column value from a Combobox

Hello Experts,

I am trying to get the value from the third column of a combo box to use a criteria in a query.  Thus far I'm using [Forms]![frmComments]![NHID], but that gives the first column and I need the third.

Thanks
0
eshurak
Asked:
eshurak
  • 5
  • 3
  • 2
  • +1
1 Solution
 
als315Commented:
[Forms]![frmComments]![NHID].Column(2)
Column nmbers are started from 0
0
 
Rey Obrero (Capricorn1)Commented:
aside from using  .column(2)
you need to make sure that the Column Count property of the combo box is set to 3
0
 
eshurakAuthor Commented:
Can't use "[Forms]![frmComments]![NHID].Column(2)" in a query.   Gives error "Undefined function '[Forms]![frmComments]![NHID].Column(2)' in expression."
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
eshurakAuthor Commented:
I don't like it but I'm going to use a dlookup instead.

dlookup("MastFacID","tblFacility","NHID = " & [Forms]![frmComments]![NHID])

0
 
eshurakAuthor Commented:
Given solutions did not work so I went with my own.
0
 
als315Commented:
You are correct. It is a new bug (feature) in Access 2010.
You can use syntax .Column(2) in VBA, in form it is now .[Column](2)
And it is impossible now to use column in query.
Very bad news.
0
 
Nick67Commented:
Much more elegant is to use a wrapper function.
Dlookup can be a performance pig.

You can't pass in the column 2 value directly

In a module, add this

Public Function TheWrapper() As Long 'or whatever data type it may be
TheWrapper = Forms!YourFormName!YourControlName.Column(2)
End Function

In the query criteria, you put
=TheWrapper()

and it works quite nicely.
This is also a good technique to pass in Global variables and other things to the query editor

See the sample
Column-Syntax.mdb
0
 
eshurakAuthor Commented:
Thanks Nick.  That's a good idea as well.
0
 
Nick67Commented:
Will you be assigning points?
0
 
eshurakAuthor Commented:
Hi Nick,

Again, thanks for your suggestion, but I'm using the dlookup and not a wrapper.  As much as I'd love to give everyone points, I think it's important for the integrity of EE and the usefulness to those searching for solutions on EE that points are giving to the solutions that are actually used.

Thanks for your understanding.
0
 
Nick67Commented:
Your call.
You have posted objections and not submissions, which made me think you might be assigning points.
And I myself avoid using DLookup for anything for performance reasons.
Any solution that avoids a DLookup is usually superior in the long run.
YMMV

<points are giving to the solutions that are actually used.>
Since the solution used is usually the best solution presented, that follows.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now