473,473 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unbound Combo Box Record Selector Question

I'm using an unbound combo box on a form as a record selector. I'm
using the combo box to choose certain types of music, i.e.
Alternative, Pop, Rock, etc…and then run a report based on the
selection.

My combo box, cboMuisicType, has a simple query, qryGetType, as a row
source. This query retrieves data from my table, tblMusicTypes. This
table has 2 fields: MusicID and MusicDesc. MusicID is the primary key
and an autonumber. MusicDesc is a description of the music, i.e.
Alternative, Pop, Rock, etc…

tblMusicTypes:

MusicID | MusicDesc
1 Alternative
2 Pop
3 Rock
The combo box is also the criteria of my query, qryGetType:
[MusicForm][cboMusicType]
Right now, I have no problem choosing one of the types of music in my
combo box and generating a report based on that selection. However,
I'd like to add a choice to my combo box that would allow me to choose
all of the types of music and then generate a report. For example,
selecting the word, "All," from my combo box, cboMusicType, would
generate a report based on all of the types of music in my table,
tblMusicTypes.

So I'm wondering what the best/ simplest way to do this is.

Should I add "All" to my table, tblMusicTypes?

Thanks!

Megan
Nov 13 '05 #1
6 2745
yes or you can make a union query (do you know how to do this???), with
additional options.

Otherwise you can also change the combobox into a listbox with the
multiselection option set to true.

Let me know what would suit best.

- Nicolaas
Nov 13 '05 #2
"WindAndWaves" <ac****@ngaru.com> wrote in message news:<0A******************@news.xtra.co.nz>...
yes or you can make a union query (do you know how to do this???), with
additional options.

Otherwise you can also change the combobox into a listbox with the
multiselection option set to true.

Let me know what would suit best.

- Nicolaas


I think I know how to do a union query. It's like query1 union query2
union query3, etc... right? But I'm unsure how to use it with a combo
box.

I've never used a listbox before. So, I'll look at some posts here to
see if I can figure it out.

Thanks for the suggestions!!!

Megan
Nov 13 '05 #3
If your form has space for a list box then it would definitely be better. In
that case your user can make any selection.

Another way to do this is to add an extra field to your table that you call
something like Sel (for select) of the boolean type.

the nice thing about using a tickbox is that it will retain its value, so if
the user wants to (most of the time) print a report for Britney Spears and
Madonna, then it will retain this selection.

Here are some generic functions that I use for controlling listboxes. Note
that you need to set them to multiselect (on the Other Tab) to use these
functions. Also note that they will need some reworking for your
application.

Option Compare Database
Option Explicit
Const ModEro = 9933
'other list operations

Public Function FuCIS(FrmN As String, CtlN As String) As String
'returns a string that tells you how many controls are selected
On Error GoTo ERR
'---
Dim FRM As Form
Dim Ctl As Control
Dim Itm As Variant
Dim X As Long
Dim Y As Long
'---
Set FRM = Forms(FrmN)
Set Ctl = FRM.Controls(CtlN)
'---
For Each Itm In Ctl.ItemsSelected
X = X + 1
Next Itm
If X = 0 Then
FuCIS = "none"
Else
Y = Ctl.Recordset.RecordCount
If X = Y Then
FuCIS = "all"
Else
FuCIS = X & "/" & Y
End If
End If
xit:
Exit Function
ERR:
FuCIS = "N/A"
Resume xit
End Function
Public Function FuSLI(FrmN As String, CtlN As String, REC As Long, bNew)
'selects a particular item on a multi-selection list
'REC = the ID of the item to selected
'bnew identifies whether it should be selected or unselected
Const ProEro = 3: 'On Error GoTo err
'---
Dim FRM As Form
Dim Ctl As Control
Dim Itm As Variant
Dim I As Long
'---
Set FRM = Forms(FrmN)
Set Ctl = FRM.Controls(CtlN)
'---
For I = 0 To Ctl.ListCount - 1
If Ctl.ItemData(I) = REC Then
Ctl.Selected(I) = bNew
End If
Next I
xit:
Exit Function
ERR:
Resume xit
End Function
Public Function MultiSelectW(FRM As Form, Ctl As Control, TBL As String) As
String
'creates a WHERE statement for a multi select listbox
'the WHERE statement can filter for for IDs of the items selected
Const ProEro = 1: 'on error GoTo err
'---
Dim Row As Variant
Dim ID As Long
'---
If Ctl.ItemsSelected.COUNT < 1 Or Ctl.ListCount < 1 Then
MultiSelectW = "Where [" & TBL & "-ID]>=0"
GoTo xit
Else
For Each Row In Ctl.ItemsSelected
ID = Ctl.Column(0, Row)
MultiSelectW = MultiSelectW & "[" & TBL & "-ID]=" & ID & "
OR "
Next Row
MultiSelectW = Left(MultiSelectW, Len(MultiSelectW) - 4)
End If
xit:
Exit Function
ERR:
Call FerrorLog(ERR.Number, 0, ProEro + ModEro): Resume xit
end function
End Function



Nov 13 '05 #4
me**************@hotmail.com (Megan) wrote in message news:<5c**************************@posting.google. com>...
So I'm wondering what the best/ simplest way to do this is.

Should I add "All" to my table, tblMusicTypes?

Thanks!

Megan


Although it's not difficult to put the word "all" in your combobox,
consider letting a blank value in the combobox mean "all." For search
forms with lots of search fields it would complicate things
unnecessarily to put "all" in for each search field. It's just as
easy to check for a Null value as an "all" value. It also makes sense
when you think of filtering records based on a value. No value means
no filtering. Here "no filtering" means having no WHERE clause.
Note: some people like to use the Report's Filter property to specify
criteria. The reason using blank values for "all" works reasonably
well is that people seldom search for values that are Null.

James A. Fortune
Nov 13 '05 #5
Hey-

Thanks for your suggestions and time! I truly appreciate it!

If you don't mind, I'd like to pose this follow-up hypothetical
situation...

1.) What if I add "All" to my table, tblMusicTypes,
tblMusicTypes:

MusicID | MusicDesc
1 Alternative
2 Pop
3 Rock
4 All

2.) Use this SQL statement:

SELECTMusicID, MusicDesc FROM tblMusicTypes UNION SELECT NULL AS
AllChoice, "(All)" AS cboAll FROM tblMusicTypes;

I was reading through the newsgroup and saw a link to the web site,
The Access Web (http://www.mvps.org/access/). On their Form's page,
they had this situation and a possible solution-- a union query as
"WindAndWaves" suggested.

But...I'm unsure of the code, such as the word "AllChoice." Is this an
Access keyword?

Plus, are the "()" needed around the word, All, in the part: "(All)"
AS cboAll FROM tblMusicTypes;

I'm going to try this, and I'll let you know how it goes so that if
anybody else has this situation, they can read this post and find a
solution!
"I'll be Baaack!" :-)

Thanks All!

Megan
Nov 13 '05 #6
me**************@hotmail.com (Megan) wrote in message news:<5c**************************@posting.google. com>...
Hey-

Thanks for your suggestions and time! I truly appreciate it!

If you don't mind, I'd like to pose this follow-up hypothetical
situation...

1.) What if I add "All" to my table, tblMusicTypes,
tblMusicTypes:

MusicID | MusicDesc
1 Alternative
2 Pop
3 Rock
4 All
Megan,

The idea behind using the Union Query was to make the word "All"
available without putting it in the table. Sometimes the criteria for
filling a combobox is more complicated than in your case and being
able to add "All" without putting it in a table is desirable. The
Union Query also allows you to put the word "All" at the beginning or
at the end of the combobox regardless of the alphabetic order that
would normally result. You could also get "All" from the table in the
spot you want by including an "ORDER BY MusicID" clause in the SQL
statement used as a RecordSource for the combobox and swapping
MusicDesc values to get the desired order.

2.) Use this SQL statement:

SELECTMusicID, MusicDesc FROM tblMusicTypes UNION SELECT NULL AS
AllChoice, "(All)" AS cboAll FROM tblMusicTypes;

If you don't put the word 'All' in tblMusicTypes then you can use
something like:

SELECT 'All' As MusicDesc, 0 As MusicID FROM tblMusicTypes UNION
SELECT MusicDesc, MusicID FROM tblMusicTypes ORDER BY MusicID;

to use the MusicID to get the desired list order or:

SELECT 'All' As MusicDesc FROM tblMusicTypes UNION SELECT MusicDesc
FROM tblMusicTypes ORDER BY MusicDesc;

to have 'All' as the first entry followed by the rest of the
selections alphabetized.

Hope this helps (hypothetically :-)),

James A. Fortune
"I'll be Baaack!" :-)

Thanks All!

Megan

Nov 13 '05 #7

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

Similar topics

7
by: Aravind | last post by:
Hi folks. I have 2 forms, frmBorrow and frmHistory frmBorrow has an unbound multi-column combo box (cboMember) and 7 unbound text boxes (MemNo, MemName, MemIC, MemType, CourseFaculty, Borrow,...
7
by: Megan | last post by:
Hi everybody- I inherited a database that somehow uses a bound combo box as a record selector. Let me give you some background. The form is based on data from 2 tables. The first table, Person,...
2
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box...
2
by: Wolfgang Kreuzer | last post by:
Hello all, I am converting an Axs 2.0 application to a2k (I know A2K is not the most current version but Axs 2.0 support ended and A2K is supported in our company amd on every PC). The form is...
1
by: BigJay | last post by:
I am 1. trying to have a combobox used as a selector to display records in a subform. and not sure on how to get selected info into subform.the combo is populated but can not get subform updated...
20
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of...
0
by: annivanova | last post by:
Hi, I saw posts in Dependent listboxes on access forms, which problem is very similar to my. I’m working over to create an MS Access application. I used in my project given code : Code:...
6
by: Rig20 | last post by:
Hello, I’m sure this is a relatively easy fix, but I have an unbound combo box on a form that runs numerous queries in the After Update section. Everything there works fine. All I need to do is...
7
by: DeZZar | last post by:
Hi all, Unfortunately I am quite a novice with Access!! I've created a number of data bases for my work however becuase my skills are limited to really built in functionality and wizards my...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.