473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using a function as the criteria for a field

I just read these 2 pages. These are most helpful, but leave me with
a question.

http://www.mvps.org/access/queries/qry0005.htm
http://www.mvps.org/access/forms/frm0007.htm

I have a Multi Select Listbox that will define query criteria for a
query that is the record source for another form.

Certain individual selections in this list box may act a label for a
group of other selections, so I am using a VBA function to create the
string that will define the WHERE clause of the SQL statement for the
query.

Quoting a portion of the above link: "Note: You can still use a
parameterized query provided you pass the entire Where clause to it
via code as a parameter. (eg. Have the query reference a hidden
control to which you manually assign the complete WHERE clause using
the following logic.)"

Assuming I understand the above quote correctly, I guess what I am
seeking is more or less syntax for assigning a complete WHERE clause
as opposed to a specific field criteria from a control.

Anybody care to give an example of this?

Chas
Apr 8 '06 #1
2 2440
I've tried a bunch, but the method below seems to be the easiest way to
implement multi-pick combo boxes. It's copied from a very generous MVP, but
I've forgotten who.

Column in Query:

IsSelectedVar("frmMyForm","cmbMyMultiPick",[myField])
Function in module:
=========================================
Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
If lbo.ItemsSelected.Count > 0 Then
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
Else
IsSelectedVar = True
End If

End Function
=========================================
<ChasW> wrote in message news:bg********************************@4ax.com...
I just read these 2 pages. These are most helpful, but leave me with
a question.

http://www.mvps.org/access/queries/qry0005.htm
http://www.mvps.org/access/forms/frm0007.htm

I have a Multi Select Listbox that will define query criteria for a
query that is the record source for another form.

Certain individual selections in this list box may act a label for a
group of other selections, so I am using a VBA function to create the
string that will define the WHERE clause of the SQL statement for the
query.

Quoting a portion of the above link: "Note: You can still use a
parameterized query provided you pass the entire Where clause to it
via code as a parameter. (eg. Have the query reference a hidden
control to which you manually assign the complete WHERE clause using
the following logic.)"

Assuming I understand the above quote correctly, I guess what I am
seeking is more or less syntax for assigning a complete WHERE clause
as opposed to a specific field criteria from a control.

Anybody care to give an example of this?

Chas

Apr 8 '06 #2
Due credit to Duane Hookom; here is the original source of the solution that
I quoted.

http://www.rogersaccesslibrary.com/Otherdownload.asp?SampleName='Listbox%20with%20Mul tiselection%20used%20in%20Query'
"Ed Robichaud" <ed*********@wdn.com> wrote in message
news:44**********************@news.wdn.com...
I've tried a bunch, but the method below seems to be the easiest way to
implement multi-pick combo boxes. It's copied from a very generous MVP,
but I've forgotten who.

Column in Query:

IsSelectedVar("frmMyForm","cmbMyMultiPick",[myField])
Function in module:
=========================================
Function IsSelectedVar( _
strFormName As String, _
strListBoxName As String, _
varValue As Variant) _
As Boolean
'strFormName is the name of the form
'strListBoxName is the name of the listbox
'varValue is the field to check against the listbox
Dim lbo As ListBox
Dim item As Variant
If IsNumeric(varValue) Then
varValue = Trim(Str(varValue))
End If
Set lbo = Forms(strFormName)(strListBoxName)
If lbo.ItemsSelected.Count > 0 Then
For Each item In lbo.ItemsSelected
If lbo.ItemData(item) = varValue Then
IsSelectedVar = True
Exit Function
End If
Next
Else
IsSelectedVar = True
End If

End Function
=========================================
<ChasW> wrote in message
news:bg********************************@4ax.com...
I just read these 2 pages. These are most helpful, but leave me with
a question.

http://www.mvps.org/access/queries/qry0005.htm
http://www.mvps.org/access/forms/frm0007.htm

I have a Multi Select Listbox that will define query criteria for a
query that is the record source for another form.

Certain individual selections in this list box may act a label for a
group of other selections, so I am using a VBA function to create the
string that will define the WHERE clause of the SQL statement for the
query.

Quoting a portion of the above link: "Note: You can still use a
parameterized query provided you pass the entire Where clause to it
via code as a parameter. (eg. Have the query reference a hidden
control to which you manually assign the complete WHERE clause using
the following logic.)"

Assuming I understand the above quote correctly, I guess what I am
seeking is more or less syntax for assigning a complete WHERE clause
as opposed to a specific field criteria from a control.

Anybody care to give an example of this?

Chas


Apr 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Reggie | last post by:
Hi and TIA, I have the criteria for one of my fields set to the return value of this function. When I view the result in the immediate window it appears to be the exact value I would use if I...
2
by: Jennifer | last post by:
I have a query with 5 possible criteria via a form. If criteria is not entered, I use the like Nz() function on the backend query to use an "*" for criteria fields left blank. The query is not...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
4
by: C White | last post by:
Hi I am having problems with running a query that does the following there are 5 fields in a table that the query is based on, the first four are simple enough and all that happens is that the...
1
by: wayneh | last post by:
I have an option group on a form with three choices "Yes/No/All" I'm using a switch function in a query to filter records on a Yes/No field. There is no problem displaying records that are either...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
1
by: paquer | last post by:
I have a form with a field who's Visible property by default is set to false. If another field meets a certain criteria, then the visible property is set to true. This form shows multiple...
5
by: turtle | last post by:
Background: I have a table of fields each field representing a month (Jan, Feb, Mar...). These are not a date field but more of a bucket to hold labor actuals. Along with the months their is...
7
by: nhkam | last post by:
I am using MS Access 2007 I have a transaction table which holds all records with posting date on each of them. I used a make table query to find out the max date hold in the transaction table and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.