473,883 Members | 3,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a combobox for searching multiple fields in "option group"

LeighW
73 New Member
Hi,

I'm still having a couple problems with searches.
I have a search form, frm_Search.
The form I am trying to filter, frm_Form1
An unbound combobox on frm_Search, Cbo_Permit
6 different fields bound to tbl_Table1 within frm_Form1, fld_Permit1, fld_Permit2...

The 6 bound fields are within a custom made "option group" so that users can select the related permit(s) via check boxes. I understand this is a poor design because of multiple fields in the table but it looks good on the form and each record can have multiple permits.

What I would like, is to use an unbound combobox within frm_Search, Cbo_Permit, using the names of the fields I shown above. The user then selects a permit within the combobox and presses a command button to open frm_Form1 filtered to that particular permit.

I need to know if this is possible as it will be one of the main searches users will make.

With other searches I've used the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SOMEBUTTON_Click()
  2.  
  3. Dim MyVar
  4.  
  5. MyVar = "[SOMEFIELD] = " & SOMECOMBOBOX.Value & "" 'This is the filter
  6.  
  7. DoCmd.OpenForm "SOMEFORM", WhereCondition:=MyVar 'This opens the form with the filter above.
  8.  
  9. End Sub
The problem is, this code only filters by one field and I need to filter by multiple fields.

Any help would be great,

Leigh
Aug 21 '12 #1
32 6215
twinnyfo
3,653 Recognized Expert Moderator Specialist
Leigh,

If I understand you correctly, you want the frm_Search to filter records in frm_Form1 based on the value of the combo box in which if someone selects Permit1, then the form will only show records in which Permit1 is used, if the user selects Permit2, then only Permit2 records, and so on.... Is this correct?

First, it would be nice to know if the permit fields are text fields or Yes/No check boxes. I would recommend making them Yes/No fields, because then this code is incredibly easy. Assuming this is the case, I would remove the Option Group (because I'm not sure it works well covering multiple fields anyway, and replace it with just your six Check Boxes (chkPermit1, chkPermit2, etc.).

Then, when someone selects any of those check boxes, after they click a command button (we'll call it cmdSearch) the following code fires:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdSearch_Click()
  5. On Error GoTo EH
  6.     Dim strFilter as String
  7.     strFilter = "fld_Permit1 = " & Me.chkPermit1 & _
  8.         "fld_Permit2 = " & Me.chkPermit2 & _
  9.         "fld_Permit3 = " & Me.chkPermit3 & _
  10.         "fld_Permit4 = " & Me.chkPermit4 & _
  11.         "fld_Permit5 = " & Me.chkPermit5 & _
  12.         "fld_Permit6 = " & Me.chkPermit6
  13.     DoCmd.OpenForm "frm_Form1", , , strFilter
  14.     Exit Sub
  15. EH:
  16.     MsgBox Err.Number & " " & Err.Description
  17.     Exit Sub
  18. End Sub
  19.  
Again, this is my recommendation, that the Permit fields are Yes/No. If not, then you can modify the code above slightly so that you would check to see whether or not there is a value in fld_Permit1, fld_Permit2 etc., based on whther or not the check boxes have been clicked.

Hope this helps, or at least gets you pointed in the right direction.
Aug 21 '12 #2
LeighW
73 New Member
Thank you again twinnyfo.

The permit fields are yes/no check boxes like you expected. I've changed the combobox in the search form to a set of checkboxes with a command button.

The only problem is when I click the command button with the code above it comes up with Run-Time Error 3075. Syntax error (missing operator) in query expression. It highlights the Cmd.OpenForm line but I believe it means strFilter.

Trying to edit some of the code but not working as of yet
Aug 21 '12 #3
zmbd
5,501 Recognized Expert Moderator Expert
Leigh,
run your code again... when it errors, select the debug option...
Now with the VBA editor open we can get at that string:
<ctrl><g> to open the immediate window
type ?strFilter and press enter
this will show what the string has evaluated to and you can cut and paste it back here... or it may be obvious what the issue is with it...
-z
Aug 21 '12 #4
twinnyfo
3,653 Recognized Expert Moderator Specialist
My mistake.... Line 7 should read:

Expand|Select|Wrap|Line Numbers
  1. strFilter = "WHERE fld_Permit1 = " & Me.chkPermit1 & _
  2.  
Aug 21 '12 #5
LeighW
73 New Member
No worries but still saying the same thing.

Expand|Select|Wrap|Line Numbers
  1. ?strFilter
  2. WHERE fld_Permit1 = -1fld_Permit2 = fld_Permit3 = 0fld_Permit4 = 0fld_Permit5 = fld_Permit6 = 
That is with chkPermit1 checked when pressing the command button

Thanks for the help so far though guys
Aug 21 '12 #6
zmbd
5,501 Recognized Expert Moderator Expert
Try changing the code to this...
you need spaces inbetween each fld_permit*

Expand|Select|Wrap|Line Numbers
  1. strFilter = "WHERE ((fld_Permit1 = " & Me.chkPermit1 & _ 
  2.         ") OR (fld_Permit2 = " & Me.chkPermit2 & _ 
  3.         ") OR (fld_Permit3 = " & Me.chkPermit3 & _ 
  4.         ") OR (fld_Permit4 = " & Me.chkPermit4 & _ 
  5.         ") OR (fld_Permit5 = " & Me.chkPermit5 & _ 
  6.         ") OR (fld_Permit6 = " & Me.chkPermit6 & "))"
  7.  
Once again... if this errors please do the <ctrl><g> thing so we can see how this evaluated.
-z
Aug 21 '12 #7
twinnyfo
3,653 Recognized Expert Moderator Specialist
Z- Good catch! I wasn't looking at the details!

Also, you will need the operator " AND " between all ... Like this:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database 
  2. Option Explicit 
  3.  
  4. Private Sub cmdSearch_Click() 
  5. On Error GoTo EH 
  6.     Dim strFilter as String 
  7.     strFilter = "fld_Permit1 = " & Me.chkPermit1 & _ 
  8.         " AND fld_Permit2 = " & Me.chkPermit2 & _ 
  9.         " AND fld_Permit3 = " & Me.chkPermit3 & _ 
  10.         " AND fld_Permit4 = " & Me.chkPermit4 & _ 
  11.         " AND fld_Permit5 = " & Me.chkPermit5 & _ 
  12.         " AND fld_Permit6 = " & Me.chkPermit6 
  13.     DoCmd.OpenForm "frm_Form1", , , strFilter 
  14.     Exit Sub 
  15. EH: 
  16.     MsgBox Err.Number & " " & Err.Description 
  17.     Exit Sub 
  18. End Sub
  19.  
Aug 21 '12 #8
zmbd
5,501 Recognized Expert Moderator Expert
I'm also thinking that you may need to default the checkboxes (me.chkpermit#) to false... depends on how the table is setup, are the fields null, true, or false, that we're looking at... this might be a better build to use the afterupdate event in each checkbox to help build the string...

-z
Aug 21 '12 #9
LeighW
73 New Member
After trying Z's method I get the same error just more syntax:

Expand|Select|Wrap|Line Numbers
  1. ?strFilter
  2. WHERE ((fld_Permit1 = -1) OR (fld_Permit2 = ) OR (fld_Permit3 = ) OR (fld_Permit4 = ) OR (fld_Permit5 = ) OR (fld_Permit6 = ))
Twinnyfo: I'm not sure what you mean by the AND when the OR has been placed there using Z's method? Do mean place the words AND OR together?

Z: The bound fields are checked either true or false on frm_Form1 and on the search form I have an unbound set of checkboxes which should also be true or false but I guess they could also be "null"
Aha that may be the problem.
Aug 21 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5173
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is 4,294,967,295. Suppose the PRIMARY key data type is set to "RANDOM" AutoNumber. Suppose an application (a) successfully INSERTS "X" records, then (b) successfully DELETES "Y" records (X >= Y), then
2
1795
by: Alpha | last post by:
It's handy to have the blue sqare mark on all the resutls of the Found lines but how do I remove it once I'm done with that? Thanks, Alpha
4
1351
by: Phill W. | last post by:
Is there anything amiss with the newsgroup microsoft.public.dotnet.vb.general ?? From where I'm sitting, it's /completely/ dried up - only four posts in as many days. Did I miss the mass exodus, or is my news server simply messing me about?
2
2463
by: ntsNews | last post by:
Hi, Using the built in command "Find Next" is there a way to have the Match Drop Down Menu to default to "Start of Field"... or can it be the only option? GCM
5
1889
by: Greg Smith | last post by:
I am making the step from windows to web. The final destination is our production server running Server 2003 Web Edition. I am having problems using the BUILD | PUBLISH WEB SITE option. What are the basic steps to publish a simple web site? All examples I can find use the local server. I am looking for something like. 1. Create a "New web site" selecting the "File System" option.
8
5558
by: wecka | last post by:
Does any one know to bound the choices of an option group to a table. Table structure is ID, Text which shall map to Text, Value for the radio buttons repectively. Appreciate advice. - Hany
3
16401
by: Robert Kilroy | last post by:
Greetings, I've been working on this for a few hours now. It seems to be a pretty simple task but I keep running into " has no properties". I have a select box defined as follows: <SELECT MULTIPLE NAME="myOptions" SIZE=5> <OPTION VALUE="Blue">Blue</OPTION> <OPTION VALUE="Red">Red</OPTION>
6
7139
by: cepera | last post by:
Hi guys! How I can retrieve "option value" info from select tag? I am using this code, but it is only let me get "name". I need to pass this value to second select tag. I found this code here: http://adamv.com/dev/javascript/http_request but they do not have any instructions how to retrieve option values. ----------JS------------
482
28066
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
9944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11154
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10863
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10422
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7136
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5807
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6005
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.