473,387 Members | 1,745 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.

Use fields on form as a criterium for a query?

I have a form that gets filtered on several fields but the OKGR_ID is
not one of them.
OKGR_ID is a numeric field.
I would like to use those values in a query

Select *
>From MyQuery
Where (the Groupnumber equals one of the values mentioned on the form
in the field OKGR_ID)

Any suggestions as to how I can do this?

Sep 19 '06 #1
7 1475

Henrootje schreef:
I have a form that gets filtered on several fields but the OKGR_ID is
not one of them.
OKGR_ID is a numeric field.
I would like to use those values in a query

Select *
From MyQuery
Where (the Groupnumber equals one of the values mentioned on the form
in the field OKGR_ID)

Any suggestions as to how I can do this?
I am rereading this and realising I am not very clear... I have a form
that gets filtered in different ways, based on different fields. One of
the fields always shown is OKGR_ID, which contains a numeric value. So
after filtering I might have 6 rows, next time 14, after that several
100 and so on and so on.

Now I have a query that contains the field GroupNumber which is numeric
too and of the same format and length. In fact they are the same except
for their names.

Now I would like to use all the number shown on my form to be used as
criteria in my query.

Select *
>From MyQuery
Where (the Groupnumber equals one of the values mentioned on the form
in the field OKGR_ID)

I found some code here in a thread with title 'use values from FORM in
query "IN" statement' but that is too complicated for me to understand
:s Is there anyuone able and willing to help me?

Sep 19 '06 #2
Whatever query you are using to show the numbers on the from needs to
be used in your new query. If the query is not specifically saved when
you look at the control in design view for that control item on the
form, then open that up and then save it as a real saved query, then
write your new query that has the just saved query as one of the
files/queries in it and that matches records based on the numbers in
that query.

Ron

Sep 19 '06 #3
The latter part, "where the number is one of a set" is best done using
an INNER JOIN between your table and the set of numbers.

What is not clear to me, still, is how you arrive at your set of
numbers. If explaining yourself in Dutch seems a helpful step, be my
guest, do so at bas apestaartje heuveltop punt ennel (now would any
spambot see that as a valid mailadress? :D)

The general idea though in that case is formulated well by Ron2006. Get
a saved query and join to that.

--
Bas Cost Budde
Holland
Sep 19 '06 #4
Thanks for thinking with me but I have it solved!!!
I found the following code and adapted it to my needs.
After defining the querysyntax, I created a temp query (from code) end
using that sql syntax to transferspreadsheet the found data!

SQL = "select mytable.* from mytable where Fieldname in ("
Dim RS As Recordset: Set RS = Forms!Formnae.RecordsetClone
If RS.RecordCount 0 Then RS.MoveFirst
While RS.EOF = False
SQL = SQL & Str$(RS!Fieldname) & ","
RS.MoveNext
Wend
Set RS = Nothing
If Right(SQL, 1) = ")" Then
SQL = SQL & "null)"
Else
Mid(SQL, Len(SQL), 1) = ")"
End If

But now I want to adapt one more thing but that won't work:
I want this part Str$(RS!Fieldname) to be dynamic:

Using something like:

Dim sColumn
Dim Fieldname

sColumn = Fieldname
sFieldname= "Str$(RS!" & sColumn & ")"

This

So if I want to reuse this code with a different field I can simply
change the "sColumn =" ..
But if I do it as shown above gets added to the query as a string :
SQL = SQL & "Str$(RS!Fieldname)" & ","
How do I prevent that sFieldname is considered a string?
Bas Cost Budde schreef:
The latter part, "where the number is one of a set" is best done using
an INNER JOIN between your table and the set of numbers.

What is not clear to me, still, is how you arrive at your set of
numbers. If explaining yourself in Dutch seems a helpful step, be my
guest, do so at bas apestaartje heuveltop punt ennel (now would any
spambot see that as a valid mailadress? :D)

The general idea though in that case is formulated well by Ron2006. Get
a saved query and join to that.

--
Bas Cost Budde
Holland
Sep 21 '06 #5
SQL = SQL & "Str$(RS!Fieldname)" & ","
How do I prevent that sFieldname is considered a string?
SQL = SQL & "str(rs(" & sFieldname & "),"
--
Bas Cost Budde
Holland
Sep 21 '06 #6


Bas Cost Budde schreef:
>SQL = SQL & "Str$(RS!Fieldname)" & ","
How do I prevent that sFieldname is considered a string?
I mean
SQL = SQL & "str(rs(" & sFieldname & ")),"
(that's 2 closing brackets)
--
Bas Cost Budde
Holland
Sep 21 '06 #7
Dank je Bas!

Thank you Bas

Bas Cost Budde schreef:
Bas Cost Budde schreef:
SQL = SQL & "Str$(RS!Fieldname)" & ","
How do I prevent that sFieldname is considered a string?

I mean
SQL = SQL & "str(rs(" & sFieldname & ")),"

(that's 2 closing brackets)
--
Bas Cost Budde
Holland
Sep 21 '06 #8

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

Similar topics

5
by: ND | last post by:
I need to create a separate field from 4 fields, "street address", "city", "State" and "zip code". For example, Street address - 100 Forest Street City - Seattle State - WA Zip - 05555 ...
0
by: cleophas | last post by:
Hi there, I have the following Access-related problem. Given a set of problems, which have several alternatives (possible solutions) and criteria for these solutions, I need to give values for...
3
by: C. Cleophas | last post by:
Hi there, I have the following Access-related problem. Given a set of problems, which have several alternatives (possible solutions) and criteria for these solutions, I need to give values for...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
6
by: Mark | last post by:
Hello. I have an MS Access 2000 form whose fields I need to read and write from VBA. The fields are data-bound, using a query that has been defined and saved in my Access database. The query...
9
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user...
3
by: Henrootje | last post by:
Hello folks, I have a groupBy query, in one of the columns (SNISNU_KWARTAAL) there is a textfield. I have an expression that deducts (from a numeric field) another expression that has the same...
45
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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...

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.