Hi Ember,
Okay, I think I have pieced everything together, based on the SQL statement
you provided. There appears to be (6)
tables involved in this query:
Contacto (Contact people within a supplier)
Equipamento
Fornecedor (Suppliers)
Guia (Orders)
Reparacao
Tipo de Transporte
In addition to the relationships you indicated, I believe the following
relationships are present:
Tipo de Transporte ---> Guia (1:M)
Equipamento ---> Reparacao (1:M) and
Reparacao ---> Guia (1:M)
Is all of this correct?
The Data de Envio field in the Guia table sounds like it might translate to
a date type field(?). Is this the "Order
Date" field that you mentioned in your first message, where you set the
criteria = Date()?
Being "Fornecedor.[Nome de Fornecedor]" the field wich is
connected to the control I want to use as criteria.
and
The Supplier control is in a text box...
If I understand this correctly, the name of the control on the form is
"Supplier" (without the quotes), and it's
Control Source is the Nome de Fornecedor field from the Fornecedor table.
Is this correct? I'm still not sure what the
name of the form is, so I am going to use "frmOrders" as the name. You'll
need to make the appropriate substitutions in
the SQL statement shown below, assuming that you likely named your form
something different. I assume you know that
this form must be open, with a value displayed in the Supplier field, in
order for the query criteria to work properly.
If this form is closed, you will receive a parameter prompt when you try to
run the query.
The Tipo de Transporte and N Reparao foreign key fields in the Guia table
must have values entered that match the
primary key values in the TransportID field of Tipo de Transporte and the
RepairID PK in the Reparacao table, since
there are INNER JOIN relations between the tables. My advice is to start
with a query that has no criteria at all. Make
sure it returns the number of records that you expect it to return. Then
apply the Date() criteria that you mentioned
previously. Again, verify that the query returns the expected number of
records. You might even want to set your system
clock to an earlier date, and test the query again, just to make sure that
it returns the correct number of records in
each case. Once those tests pass okay, you're ready to apply the Supplier
criteria as shown in the form.
In the SQL statement that follows, the name of the form and the name of the
control on the form is included in the
first line and in the last line. I recommend copying this SQL statement to
NotePad first, save it, and then copy it to
the SQL View of a new query. The reason I say this is that I had some
trouble with the SQL statement that I copied from
your last post, which I think might have included some non-printing
characters. Saving the text in NotePad should
eliminate any non-printing characters that might cause you grief.
PARAMETERS [Forms]![frmOrders]![Supplier] Text ( 255 );
SELECT Guia.GuiaID, Guia.[N Reparao], Reparacao.[Serial Nr],
Equipamento.Modelo, Reparacao.Motivo,
Reparacao.[Descricao da Avaria], Guia.[Data de Envio],
Reparacao.[Data de Devoluo], Guia.[Tipo de Transporte],
Guia.[Contacto de Fornecedor], Fornecedor.[Nome de Fornecedor],
Contacto.[N Telefone], Contacto.[E-Mail], Fornecedor.Endereo,
Fornecedor.[Cdigo Postal], Fornecedor.[N Contribuinte],
[Tipo de Transporte].Matrcula
FROM
[Tipo de Transporte] INNER JOIN ((Equipamento
INNER JOIN Reparacao
ON Equipamento.[N Serie] = Reparacao.[Serial Nr])
INNER JOIN (Fornecedor INNER JOIN (Contacto INNER JOIN Guia ON
Contacto.ContactoID = Guia.[Contacto de Fornecedor])
ON Fornecedor.FornecedorID = Contacto.Empresa)
ON Reparacao.RepairID = Guia.[N Reparao])
ON [Tipo de Transporte].TransportID = Guia.[Tipo de Transporte]
WHERE
(((Guia.[Data de Envio])=Date())
AND
((Fornecedor.[Nome de Fornecedor])=[Forms]![frmOrders]![Supplier]));
Good Luck, and please let me know if this works for you.
Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
:
Hi,
The Supplier table (called "Fornecedor") isn't directly connected to
the Order ( called "Guia") Table.
It is connected to _an intermediate table called Contactos (the
contact persons inside the supplier), because the order is created
through the contact,
So, I have a "Supplier (One) to Contactos (Many) relation, and a
Contactos (One) to Guia (Many) Relation.
Here is the SQL string for the query i'm using in the form:
SELECT Guia.GuiaID, Guia.[N Reparao],
Reparacao.[Serial Nr],
Equipamento.Modelo,
Reparacao.Motivo, Reparacao.[Descricao da Avaria],
Guia.[Data de Envio],
Reparacao.[Data de Devoluo],
Guia.[Tipo de Transporte], Guia.[Contacto de Fornecedor],
Fornecedor.[Nome de Fornecedor],
Contacto.[N Telefone], Contacto.[E-Mail],
Fornecedor.Endereo, Fornecedor.[Cdigo Postal],
Fornecedor.[N Contribuinte],
[Tipo de Transporte].Matrcula
FROM [Tipo de Transporte]
INNER JOIN ((Equipamento INNER JOIN Reparacao
ON Equipamento.[N Serie] = Reparacao.[Serial Nr])
INNER JOIN (Fornecedor INNER JOIN (Contacto INNER JOIN
Guia ON Contacto.ContactoID = Guia.[Contacto de Fornecedor])
ON Fornecedor.FornecedorID = Contacto.Empresa)
ON Reparacao.RepairID = Guia.[N Reparao])
ON [Tipo de Transporte].TransportID = Guia.[Tipo de Transporte];
Being "Fornecedor.[Nome de Fornecedor]" the field wich is connected to
the control I want to use as criteria.
P.S. - The Supplier control is in a text box, and it is formatted as
text.
Thanks all for your help,
ember