473,651 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query By Form Like Statement

I'm trying to search by form a field in a table called 'subject' via
two combo boxes on a form. In the query I have the following criteria
in the 'Subject' field:

(Like "*" & [Forms]![frmFind]![cmbOp] & "*") Or (Like "*" &
[Forms]![frmFind]![cmbSub] & "*")

This seems to work fine untill I leave either [cmbOp] blank, or
[cmbSub] blank - at which point it returns ALL records with no blank
Subject field. Any ideas?

many thanks

jon

Nov 13 '05 #1
1 2566
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Instead of using the Form reference in the query, you'll have to
dynamically create the SQL string in VBA. E.g.:

If not IsNull(Me!cmbOp ) Then
strWhere = strWhere & " Like "'*" & Me!cmbOp & "*'"
End If

If Not IsNull(me!cmbSu b) Then
strWhere = strWhere & " Like '*" & Me!cmbSub & "*'"
End If

If Len(strWhere)>0 Then
strSQL = strSQL & strWhere
End If

'.... then put the SQL string into a QueryDef
' CurrentDb.Query Defs("myQuery") .SQL = strSQL

' or get a recordset
set rs = db.openrecordse t(strSQL)

.... etc. ...

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQdmXzoechKq OuFEgEQIwewCglM vI0jz2XkZDnGbNY 8EV+HFaxNAAoIUp
9H5O1Rz61UstPjJ bspkFMynn
=+Rkj
-----END PGP SIGNATURE-----
jonhanks wrote:
I'm trying to search by form a field in a table called 'subject' via
two combo boxes on a form. In the query I have the following criteria
in the 'Subject' field:

(Like "*" & [Forms]![frmFind]![cmbOp] & "*") Or (Like "*" &
[Forms]![frmFind]![cmbSub] & "*")

This seems to work fine untill I leave either [cmbOp] blank, or
[cmbSub] blank - at which point it returns ALL records with no blank
Subject field. Any ideas?

Nov 13 '05 #2

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

Similar topics

1
3673
by: ITHELP | last post by:
I am using a form to find some data from a table. In the table are fields such as Client name, job number, and job description. I built a query using a SQL statement through the 'Record source' for the form. I can get the query to work if I type in the Client name exactly as it is in the table. However, I want to be able to use a like statement to expand my search and find all records with a certain word or year in it. How can I get this...
3
579
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields that are headed in various categories and are yes/no formated
3
6166
by: DFS | last post by:
I've been working around this for years (I believe), so I figured someone here might know: Why won't a crosstab query accept a value from a form reference? TRANSFORM Format(First(QtrAvg),'Fixed') AS FirstQtrAvg SELECT PropertyCode, Survey, Question FROM SurveyData WHERE PropertyCode = Forms.MainForm.Subform.Form.PropertyCode GROUP BY PropertyCode, Survey, Question
6
1682
by: Liz Malcolm | last post by:
Hello and Thanks in advance for any help. I am using Access 2000. I have a data entry form that opens a main form (using the On Click event of the combo box ) with tab controls and 1 subform on the last tab control. The main form is opened using a where clause to restrict the contact type. The subform is built on a separate table that lists other contact types that the contact could be a member of. Example a volunteer could also be a...
0
3497
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
3
1974
by: dskillingstad | last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong, but.... I've searched these groups for some solutions but no luck. I have an unbound form (frmSearch), with several unbound text boxes on it and a command button bound to a macro which fires off a parameter query based on the criteria/string that the user types into the text boxes on frmSearch. My goal is to create a search form where the user can search by any of...
0
8657
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information with others. I have seen many request for information on mail merging an how to send data to word documents this is something I have put together with the answers given by others and I hope this will help a few newbies , I know there are easier ways...
9
3048
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
2
4524
by: Bob Alston | last post by:
If you have an access form with record source being a straightforward query and where clause in the form definition, will the query be sent to the back end jet/Access database and executed there, withonly the record(s) meeting the criteria being returned to the front end? Is JetShowPlan a good tool to see that this is working? Bob
1
4275
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on another main and sub form. The requery on the sub form and refresh comands on the main form do not work when the form is first displayed and when the selection criteria is changed. Should I be doing a refresh and then repaint of the sub form. ...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8697
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
8465
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
8579
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...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
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
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.