populating list on criteria

H

hinterbichler

I have a Form and Subform. Now on the subform I have a listbox where I
want to display only records that match certain criteria from the sub
form. I can list all the records from the table but struggle on the
criteria problem.
The form is called Devices the Subform is called Inputs. list records
according to ProjID,Device and DevNum.
Any help would be greatly appreciated.
 
H

hinterbichler

I am very new to databases and therfor not sure how to explain this
correctly.
Here we go.
The main form called Devices is from a table that has info for the
differnt Control Devices that I am using and is related to a table
with Customer info (name, address and "ProjID", etc.)
The Subform on this form is where I iput all info for various Input
devices (a table called Inputs) that can control the Control device.
Now every one of this Input Devices depends on or is related to
the Customer "ProjID" stored in the table Inputs, the Control Device
itself "ConDev" and its Number "ConNum" all of these are also in the
Input table that I want to query.
Every customer can have the same Control Device and its number and the
same Input device.
I want to when I select a differnt Control Device (different record)
on the Main form "Devices" to show in the subform on a listbox the
assosiated Input devices according (or filtered) to "ProjID" (which is
the Customer)
the Control Device "ConDev" and its number "ConNum".
I hope that clears things up.
 
M

Michael Gramelspacher

I am very new to databases and therfor not sure how to explain this
correctly.
Here we go.
The main form called Devices is from a table that has info for the
differnt Control Devices that I am using and is related to a table
with Customer info (name, address and "ProjID", etc.)
The Subform on this form is where I iput all info for various Input
devices (a table called Inputs) that can control the Control device.
Now every one of this Input Devices depends on or is related to
the Customer "ProjID" stored in the table Inputs, the Control Device
itself "ConDev" and its Number "ConNum" all of these are also in the
Input table that I want to query.
Every customer can have the same Control Device and its number and the
same Input device.
I want to when I select a differnt Control Device (different record)
on the Main form "Devices" to show in the subform on a listbox the
assosiated Input devices according (or filtered) to "ProjID" (which is
the Customer)
the Control Device "ConDev" and its number "ConNum".
I hope that clears things up.

You have a table Customers and a table Projects.

You have a relationship Customers-Projects.

You have a table Devices and a relationship Projects-Devices.

Can a project use more than one of the same device? If so, you need
a quantity.

You have a table Inputs, which seems like it is really the same thing as
Devices except used differently.

You have a relationship Projects-Devices-Inputs.

Can a project device use more than one of the same input?

The tables and relationships must be modeled correctly before the model
can be implemented. Forms, subforms, listboxes, etc., have to do with
implementation.
 
H

hinterbichler

Thanks for all the explanations so far.

Table Customers is a follows
tblCust
ID txtProjID txtCustName
2 P0002 XX Industries

Table Devices
tblUsedDev
ID txtProjID txtConDev numDev
9 P0002 16 IN-EXP 1

Table Inputs
tblInput
ID txtProjID txtConDev numDev numIn txtInDev
13 P0002 16 IN-EXP 1 1 REX

Now "txtInDev" which I select from a dropdownbox can be used with any
Customer.
The relationships are at the moment with the fields ID between the
three tables as one-to-one.
The flow is as follows.

txtInDev "REX" with "numIn" of 1 is used with Cuatomer P0002 on a
device called 16 IN-EXP with the number 1
(there can be many of the type 16 IN-EXP with one customer but not
with the same "numDev"
they are different). And on a second 16 IN-EXP (number 2) there can be
a "REX" with "numIn" of 1
for the same customer.

Hope this explains it further.

Christian
 
H

hinterbichler

Just to add to my post above.
In the listbox (on the subform Inputs) I would like to list the
following

From table Inputs

The all "numIn" on the same "txtConDev" with the same number
"numDev" for the same customer "txtProjID".


Christian
 
M

Michael Gramelspacher

Just to add to my post above.
In the listbox (on the subform Inputs) I would like to list the
following

From table Inputs

The all "numIn" on the same "txtConDev" with the same number
"numDev" for the same customer "txtProjID".


Christian

This is basically the structure you already have.
Create a new database with a new module and
copy and paste this code into the module and save it.

Type call CreateTablesDDL in the Immediate window
and press enter. This creates the tables. This is only meant
to be an example.

It can be implemented as a main form on CustomerProjects and
two subforms on ProjectControlDevices and ProjectControlInputDevices.

Sub CreateTablesDDL()

With CurrentProject.Connection

.Execute _
"CREATE TABLE Customers " & _
"(" & _
"customer_id VARCHAR (10) NOT NULL, " & _
"customer_name VARCHAR (50) NOT NULL, " & _
"PRIMARY KEY (customer_id) " & _
");"

.Execute _
"CREATE TABLE Projects " & _
"(" & _
"project_id CHAR (5) NOT NULL, " & _
"project_name VARCHAR (50) NOT NULL, " & _
"PRIMARY KEY (project_id) " & _
");"

.Execute _
"CREATE TABLE CustomerProjects " & _
"(" & _
"customer_id VARCHAR (10) NOT NULL " & _
"REFERENCES Customers (customer_id), " & _
"project_id CHAR (5) NOT NULL " & _
"REFERENCES Projects (project_id), " & _
"PRIMARY KEY (customer_id, project_id) " & _
");"

.Execute _
"CREATE TABLE ControlDevices " & _
"(" & _
"condev_name VARCHAR (30) NOT NULL, " & _
"condev_num INTEGER NOT NULL, " & _
"PRIMARY KEY (condev_name, condev_num) " & _
");"

.Execute _
"CREATE TABLE ProjectControlDevices " & _
"(" & _
"project_id CHAR (5) NOT NULL " & _
"REFERENCES PROJECTS (Project_id), " & _
"condev_name VARCHAR (30) NOT NULL, " & _
"condev_num INTEGER NOT NULL, " & _
"CONSTRAINT fk_controldevices " & _
"FOREIGN KEY (condev_name, condev_num) " & _
"REFERENCES ControlDevices " & _
"(condev_name, condev_num), " & _
"PRIMARY KEY (project_id, condev_name, condev_num) " & _
");"

.Execute _
"CREATE TABLE InputDevices " & _
"(" & _
"indev_name VARCHAR (30) NOT NULL, " & _
"indev_num INTEGER NOT NULL, " & _
"PRIMARY KEY (indev_name, indev_num) " & _
");"

.Execute _
"CREATE TABLE ProjectControlInputDevices " & _
"(" & _
"project_id CHAR (5) NOT NULL, " & _
"condev_name VARCHAR (30) NOT NULL, " & _
"condev_num INTEGER NOT NULL, " & _
"CONSTRAINT fk_projectcontroldevices " & _
"FOREIGN KEY (project_id,condev_name, condev_num) " & _
"REFERENCES ProjectControlDevices " & _
"(project_id, condev_name, condev_num), " & _
"indev_name VARCHAR (30) NOT NULL, " & _
"indev_num INTEGER NOT NULL, " & _
"CONSTRAINT fk_inputdevices " & _
"FOREIGN KEY (indev_name, indev_num) " & _
"REFERENCES InputDevices (indev_name, indev_num), " & _
"PRIMARY KEY (project_id, condev_name, condev_num, " & _
"indev_name, indev_num) " & _
");"

End With

End Sub
 
H

hinterbichler

Thanks Michael

Will work on it over the week end.
Not sure yet how to go about it with the structure you suggested.

Christian
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
J

Jan Baird

Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top