473,320 Members | 2,124 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,320 software developers and data experts.

Creating query based on form

I am creating a contact database and I would like the user to create
his own groups of contacts based on criterias, thefore I would like to
let him pick the fields and criteria for a particular group. I don't
wanna a form full of fields that ask the user for arguments. Instead a
subform with a combobox where the user picks the [field], the
[operator], and the [arguement]

So I would have two tables groups and GroupCriteria for instance:

group field operator criteria
____________________________________

Accounts city = brooklyn

Accounts status < active
I then would live to each record to supply the query with these
arguements. Is the wrong way to go about it? How can I create my own
arguement. I see examples on how to pass but how do I create it using
code?

Sep 8 '06 #1
5 2889
this is the function that I am thinking might do it:

Function getsource(group)

End Function
Dim rec As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Dim sql As String
Dim qdf As QueryDef
Dim strsql As String
Dim fieldn As String
Dim oper As String
Dim crit As String
Dim surplus As String

Set rec = db.OpenRecordset("select * from tblGroupCriteria where
groupid = " & group)

strQueryName = "qryTemp"
If ((rec.BOF) And (Not rec.EOF)) Then
strsql = "SELECT * from tblIndividuals"
Set qdf = db.CreateQueryDef(strQueryName, strsql)
Exit Function
End If

strsql = "SELECT * from tblIndividuals where "
With rec
If Not .EOF Then
fieldn = !FieldName
oper = !Operator
crit = !Criteria
End If
surplus = fieldn & " " & oper & " " & crit & "and"
strsql = strsql & surplus

Do While Not .EOF
fieldn = !FieldName
oper = !Operator
crit = !Criteria
surplus = "and" & fieldn & " " & oper & " " & crit
strsql = strsql & surplus
Loop
End With

End Function

Sep 8 '06 #2

Kaspa wrote:
I am creating a contact database and I would like the user to create
his own groups of contacts based on criterias, thefore I would like to
let him pick the fields and criteria for a particular group. I don't
wanna a form full of fields that ask the user for arguments. Instead a
subform with a combobox where the user picks the [field], the
[operator], and the [arguement]

So I would have two tables groups and GroupCriteria for instance:

group field operator criteria
____________________________________

Accounts city = brooklyn

Accounts status < active
I then would live to each record to supply the query with these
arguements. Is the wrong way to go about it? How can I create my own
arguement. I see examples on how to pass but how do I create it using
code?
off the top of my head (do I ever do anything any other way?), You
could open a recordset of all the records for a specific group, e.g.
SELECT Group, Field, Operator, Criteria
FROM GroupCriteria
WHERE group = <point at a form here?>

Then you could simply walk through the recordset...

do until rs.EOF
strFilter = strFilter & " AND " &
rs.Fields("Field") & rs.Fields("Operator") & fDelimiter(fieldType)
& rs.Fields("Value") & fDelimiter(fieldType)

rs.MoveNext

Loop

or you could save these as different queries (just not let the user see
them)...

Sep 8 '06 #3
Kaspa,

I was thinking along the same lines (doesn't make it right, mind you).
One thing I thought about, though, is delimiters - stuff that the QBE
grid puts in there for you. (so maybe if you build querydefs on the
fly, you may not need them). you might want to check field types so
that you're sure you include delimiters for literal values, like dates
(#), strings ('), etc.

I guess if you wait for the other folks here to sleep and have coffee,
you'll get more answers.

but that's my two cents... at a discount.

Pieter

Sep 8 '06 #4
thank you for that, I was not think about it.
pi********@hotmail.com wrote:
Kaspa,

I was thinking along the same lines (doesn't make it right, mind you).
One thing I thought about, though, is delimiters - stuff that the QBE
grid puts in there for you. (so maybe if you build querydefs on the
fly, you may not need them). you might want to check field types so
that you're sure you include delimiters for literal values, like dates
(#), strings ('), etc.

I guess if you wait for the other folks here to sleep and have coffee,
you'll get more answers.

but that's my two cents... at a discount.

Pieter
Sep 8 '06 #5
Anybody else has any input?
pi********@hotmail.com wrote:
Kaspa wrote:
I am creating a contact database and I would like the user to create
his own groups of contacts based on criterias, thefore I would like to
let him pick the fields and criteria for a particular group. I don't
wanna a form full of fields that ask the user for arguments. Instead a
subform with a combobox where the user picks the [field], the
[operator], and the [arguement]

So I would have two tables groups and GroupCriteria for instance:

group field operator criteria
____________________________________

Accounts city = brooklyn

Accounts status < active
I then would live to each record to supply the query with these
arguements. Is the wrong way to go about it? How can I create my own
arguement. I see examples on how to pass but how do I create it using
code?

off the top of my head (do I ever do anything any other way?), You
could open a recordset of all the records for a specific group, e.g.
SELECT Group, Field, Operator, Criteria
FROM GroupCriteria
WHERE group = <point at a form here?>

Then you could simply walk through the recordset...

do until rs.EOF
strFilter = strFilter & " AND " &
rs.Fields("Field") & rs.Fields("Operator") & fDelimiter(fieldType)
& rs.Fields("Value") & fDelimiter(fieldType)

rs.MoveNext

Loop

or you could save these as different queries (just not let the user see
them)...
Sep 8 '06 #6

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

Similar topics

2
by: Iain Miller | last post by:
Now this shouldn't be hard but I've been struggling on the best way as to how to do this one for a day or 3 so I thought I'd ask the assembled company..... I'm writing an application that tracks...
4
by: Jeremy Weiss | last post by:
Thanks to much help from everyone in my previous thread, I've made it a pretty fair ways into my billing/invoicing db. I'm now needing a way to cycle through all the records in a table and create...
3
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
1
by: Trent | last post by:
I am in the design phase of a new database and am having a devil of a time with a subform. I have three tables that relate to problem - Suppliers tbl, Customers tbl and a SuppliersCustomers tbl....
1
by: sunrisewinesalon | last post by:
New here--I posted this to another group called 'ms access problems,' but it only had one member... Access says you can choose fields from more than one table or query to create a form--but can...
3
by: rreitsma | last post by:
I want to create a form that will allow the user to select from a list of available reports and based on a filter limit the records displayed in the report. I have figured out how to access the...
4
by: DeanL | last post by:
Hi Guys, I need some help creating a query that is going to take between 1 and 10 parameters. The parameters are entered on a form into text boxes that may have data or be empty. Is there a...
0
by: FrozenDude | last post by:
Hello and thanks in advance. I've read through the threads but can't seem to make this work. I have a form with a combo box (named DateCode) that provides a table column name and a subform...
1
by: MikeMikerson | last post by:
Hello, I am need to create a subform (no problem) of a form based query (a problem). I need a form that will prompt the user to enter in a name, and the form will then display a query of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.