473,656 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem quith query criteria

Hi everyone,

I have this slq code

slqtext = "SELECT [total_installs].[Unité Administrative] From
total_installs, uachoisi WHERE ((([total_installs].[Unité
Administrative])='*afe*'));"

which makes a query that only accept values containing "afe". It works
perfectly.

Here's the problem : I would like to change the "*afe*" part for the
value of a table. Something like "*[table].[value]*" cause the value
changes while my program is running.
Any ideas ?

Plz excuse my poor english.

Alex

Aug 3 '06 #1
4 1771
"icony" <al**********@h otmail.comwrote in
news:11******** **************@ i3g2000cwc.goog legroups.com:
Hi everyone,

I have this slq code

slqtext = "SELECT [total_installs].[Unité Administrative] From
total_installs, uachoisi WHERE ((([total_installs].[Unité
Administrative])='*afe*'));"

which makes a query that only accept values containing "afe".
It works perfectly.

Here's the problem : I would like to change the "*afe*" part
for the value of a table. Something like "*[table].[value]*"
cause the value changes while my program is running.
Any ideas ?

Plz excuse my poor english.

Alex
slqtext = "SELECT [total_installs].[Unité Administrative] From
total_installs, uachoisi WHERE ((([total_installs].[Unité
Administrative])='*' & [table].[value] & '*'));"
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 3 '06 #2
Hi Alex,

You have a few options. The easiest option is to use VBA code like
this:

Private Sub Command1_Click( )
Dim DB As DAO.Database, QD As DAO.QueryDef
dim str1 As String
str1 = txt0

Set DB = CurrentDB
'--first get rid of query test1 if already exists
For Each qd In db.QueryDefs
If qd.Name = "test1" Then
db.QueryDefs.De lete qd.Name
Exit For
End If
Next
'--create new test1 query
Set QD = DB.CreateQueryD ef("test1")
QD.SQL = "SELECT " _
& "[total_installs].[Unité Administrative] " _
& "From total_installs, uachoisi " _
& "WHERE " _
& "[total_installs].[UnitéAdministra tive]='" & str1 & "'"
DoCmd.OpenQuery "test1"
End Sub

Here you have a form that is based on your table, and txt0 is a textbox
that is linked to the table and Command1 is a command button on the
form. You assign the value of txt0 to the variable str1 and use str1 in
your Sql Statement. When you click the button,

Your other option is to create a public function and a public variable
in a standard code module (not a class module). You assign a value to
the public variable. Place the public function in the sql code in the
Query window. The function will take the value of the variable:

Public globalStr1 As String

Public Function funcStr1() As String
funcStr1 = globalStr1
End Function

In the sql in your query add the function to the criteria section of
your query. Note: you have to include both parentheses ()

Field: [UnitéAdministra tive]
Criteria: funcStr1()

You can assign a value to the function from a command button on a form:

Private Sub Command1_Click( )
globalStr1 = "something"
DoCmd.OpenQuery "test1"
End Sub

With this second example, you don't have to delete the query everytime.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 3 '06 #3
Thx a lot Rich, it worked !!!

i used the first option and my slq text changed just a little from what
you wrote cause of the spaces and all. Here's what i used :

choix = combo1.text

myslqtxt = "SELECT " _
& "[total_installs].[Unité Administrative] " _
& "From total_installs, uachoisi " _
& "WHERE " _
& "((([total_installs].[Unité Administrative])LIKE'" & "*" & choix &
"*" & "'))"

keep up the good job !!

Alex

Aug 4 '06 #4
Hi Alex,

You can modify this a little bit:
>>
choix = combo1.text

myslqtxt = "SELECT " _
& "[total_installs].[Unité Administrative] " _
& "From total_installs, uachoisi " _
& "WHERE " _
& "((([total_installs].[Unité Administrative])LIKE'" & "*" & choix &
"*" & "'))"
<<

To this:

choix = combo1.text

myslqtxt = "SELECT " _
& "[total_installs].[Unité Administrative] " _
& "From total_installs, uachoisi " _
& "WHERE " _
& "((([total_installs].[Unité Administrative])LIKE '*" & choix & "*'))"

This part:

LIKE '*" & choix & "*'))"

When you use a variable in a Sql string - you have to delimit string
(text) variables with single quotes '. so you have

... '*" & variable & "*' ..."

Number variables do not require to be delimited. But Date variables
#3/1/2006# have to be delimited with # symbol. And always be sure that
you have spaces between the operators -->OR, LIKE, AND, IN, EXISTS

Like'*"... <---this is incorrect

Like '*"... <--- this is correct because you have a space

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 4 '06 #5

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

Similar topics

2
2323
by: mike | last post by:
ok here's the problem: I have a page that displays a form for user to select individual fields and to specify their own criteria which is used to query a database and then create an excel spreadsheet and download it to their PC. when the user clicks on the "create a custom query" link on the reports page the file customss.php displays the form that list the various fields and criteria to specify for the search. This part
6
3725
by: HKM | last post by:
Hello, I have a query engine that builds the SQL Query to obtain the recordSet. Following is an Exmaple Query that my QueryBuilder outputted SELECT * FROM BookInfo WHERE BookName LIKE '*cobol*' When I use this query to build recordset I get empty recordSet back when the BookInfo table has entries that qualify for this criteria. To
1
357
by: Tero Partanen | last post by:
Hi, I have a small problem with MS ACCESS query. I want to be able to have a field, where I can input the search parameter, and then it will show me all the entires that match the parameter. I have done this already (almost) using "Select Query", where in the design view I enter the parameter in the "Criteria" field of the query (under the field that I'm using for the query), but there has to be a more simple way of doing it, ie. just...
6
7114
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3 fields on it: Date (DateSpan1 and DateSpan2), Originator, and GroupName. I have added a button that triggers a query and uses those fields as its parameter criteria to populate a form. The user must be allowed to either enter all of the
5
11438
by: SuffrinMick | last post by:
Hello - I'm a newbie to coding! I'm working on an access 2000 database which has three tables: tblContacts - A list of customer contacts. tblOrgTypes - A list of organisational types. tblPositions - A list of job descriptions (Contacts can hold more than one position) I want to use a multi-select list box (Containing alphabetical list of positions) to run a query. HELP!
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...
3
4609
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using Access 97 (I know it's old. But, it's the tool they give me to work with) My working knowledge of SQL is on the low side. My working knowledge of VBA is beginner.
9
5751
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just call it Express for simplicity). I have, to try to simplify things, put the exact same DB on two systems, one running MSDE and one running Express. Both have 2 Ghz processors (one Intel, one AMD), both have a decent amount of RAM (Intel system...
0
8382
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
8816
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...
1
8498
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
7311
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...
1
6162
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
5629
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
4150
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...
1
2726
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 we have to send another system
2
1930
muto222
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.