Importing nested queries loses joins

G

Guest

Hi, I have a database that contains nested queries and I import these queries.

That is, the database contains queries that have queries as data source
(don't mean to dumb it down, just want the situation to be explicitly clear).
In the top query the source queries are joined on related fields.

The problem is that when I import (using DoCmd.TransferDatabase acImport)
all the queries involved, the joins are dropped. That is the source queries
still exist in the top query. However the joins between source queries no
longer exist.

Why is that? More importantly how can I avoid this happening?
 
V

Vincent Johns

Jonathan said:
Hi, I have a database that contains nested queries and I import these queries.

That is, the database contains queries that have queries as data source
(don't mean to dumb it down, just want the situation to be explicitly clear).
In the top query the source queries are joined on related fields.

The problem is that when I import (using DoCmd.TransferDatabase acImport)
all the queries involved, the joins are dropped. That is the source queries
still exist in the top query. However the joins between source queries no
longer exist.

Why is that? More importantly how can I avoid this happening?

I was unable to reproduce your problem. Perhaps some joined Table or
Query was missing, so Access blasted the links into oblivion; this would
be normal behavior.

If you want to try using my code, Tables, and Queries, maybe that will
shed light on your situation. (I omitted my usual error-checking code
from the VBA.) These procedures worked both when expressed as a Macro
and when defined using the following code:

'------------------------------------------------------------
' Import_Queries imports the specified Queries
' and the Tables on which they depend
'
'------------------------------------------------------------
Public Function ImportQueries()

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
Import1 acQuery, "Q_Reasons"

' Import [Q_Shipped Stuff]
Import1 acQuery, "Q_Shipped Stuff"

' Import [Q_Shipped?]
Import1 acQuery, "Q_Shipped?"

' Import [tblOrder]
Import1 acTable, "tblOrder"

' Import [tblOrderShip]
Import1 acTable, "tblOrderShip"

End Function 'ImportQueries()

'------------------------------------------------------------
' Import1() imports the specified object
'
'------------------------------------------------------------
Public Sub Import1( _
ByVal ObjectType As AcObjectType, _
ByVal ObjectName As String)

'ByVal ObjectType As AcObjectType 'acQuery _
or acTable
'ByVal ObjectName As String 'Name of Table _
or Query to import

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
DoCmd.TransferDatabase acImport, _
"Microsoft Access", _
strSourceFile, _
ObjectType, ObjectName, _
ObjectName, False

End Sub 'ImportQueries()

The (complete) contents of the two Tables are shown here:

[tblOrderShip] Table Datasheet View:

OrderShipID OrderID ShipDate ReasonNotShipped
----------- ----------- ---------- ----------------
-418235218 1945178752 Fungus
402604161 -1152314661 11/10/2005

[tblOrder] Table Datasheet View:

OrderID Status
----------- -------
-1152314661 Shipped
1945178752 Stalled

The three imported Queries are defined as follows; notice that
[Q_Shipped Stuff] includes a JOIN on [Q_Shipped?] and [Q_Reasons].

[Q_Reasons] SQL:
SELECT TblOrderShip.OrderID,
TblOrderShip.ReasonNotShipped
FROM TblOrderShip
ORDER BY TblOrderShip.ReasonNotShipped;

[Q_Shipped?] SQL:
SELECT TblOrder.OrderID, TblOrder.Status,
Count(TblOrderShip.ShipDate) AS CountOfShipDate,
[CountOfShipDate]>0 AS [IsShipped?]
FROM TblOrder INNER JOIN TblOrderShip
ON TblOrder.OrderID = TblOrderShip.OrderID
GROUP BY TblOrder.OrderID, TblOrder.Status
HAVING (((Count(TblOrderShip.ShipDate)) Is Not Null))
ORDER BY TblOrder.OrderID;

[Q_Shipped Stuff] SQL:
SELECT [Q_Shipped?].OrderID, [Q_Shipped?].Status,
Q_Reasons.ReasonNotShipped
FROM [Q_Shipped?] INNER JOIN Q_Reasons
ON [Q_Shipped?].OrderID = Q_Reasons.OrderID
WHERE ((([Q_Shipped?].[IsShipped?])=No));

[Q_Shipped Stuff] Query Datasheet View:

OrderID Status ReasonNotShipped
---------- ------- ----------------
1945178752 Stalled Fungus


-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
G

Guest

Vincent, thanks for your response.

I must admit that I'm not sure what the problem is. Maybe there is something
else happening and the only visible sign is a failed query import.

Thanks


Vincent Johns said:
Jonathan said:
Hi, I have a database that contains nested queries and I import these queries.

That is, the database contains queries that have queries as data source
(don't mean to dumb it down, just want the situation to be explicitly clear).
In the top query the source queries are joined on related fields.

The problem is that when I import (using DoCmd.TransferDatabase acImport)
all the queries involved, the joins are dropped. That is the source queries
still exist in the top query. However the joins between source queries no
longer exist.

Why is that? More importantly how can I avoid this happening?

I was unable to reproduce your problem. Perhaps some joined Table or
Query was missing, so Access blasted the links into oblivion; this would
be normal behavior.

If you want to try using my code, Tables, and Queries, maybe that will
shed light on your situation. (I omitted my usual error-checking code
from the VBA.) These procedures worked both when expressed as a Macro
and when defined using the following code:

'------------------------------------------------------------
' Import_Queries imports the specified Queries
' and the Tables on which they depend
'
'------------------------------------------------------------
Public Function ImportQueries()

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
Import1 acQuery, "Q_Reasons"

' Import [Q_Shipped Stuff]
Import1 acQuery, "Q_Shipped Stuff"

' Import [Q_Shipped?]
Import1 acQuery, "Q_Shipped?"

' Import [tblOrder]
Import1 acTable, "tblOrder"

' Import [tblOrderShip]
Import1 acTable, "tblOrderShip"

End Function 'ImportQueries()

'------------------------------------------------------------
' Import1() imports the specified object
'
'------------------------------------------------------------
Public Sub Import1( _
ByVal ObjectType As AcObjectType, _
ByVal ObjectName As String)

'ByVal ObjectType As AcObjectType 'acQuery _
or acTable
'ByVal ObjectName As String 'Name of Table _
or Query to import

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
DoCmd.TransferDatabase acImport, _
"Microsoft Access", _
strSourceFile, _
ObjectType, ObjectName, _
ObjectName, False

End Sub 'ImportQueries()

The (complete) contents of the two Tables are shown here:

[tblOrderShip] Table Datasheet View:

OrderShipID OrderID ShipDate ReasonNotShipped
----------- ----------- ---------- ----------------
-418235218 1945178752 Fungus
402604161 -1152314661 11/10/2005

[tblOrder] Table Datasheet View:

OrderID Status
----------- -------
-1152314661 Shipped
1945178752 Stalled

The three imported Queries are defined as follows; notice that
[Q_Shipped Stuff] includes a JOIN on [Q_Shipped?] and [Q_Reasons].

[Q_Reasons] SQL:
SELECT TblOrderShip.OrderID,
TblOrderShip.ReasonNotShipped
FROM TblOrderShip
ORDER BY TblOrderShip.ReasonNotShipped;

[Q_Shipped?] SQL:
SELECT TblOrder.OrderID, TblOrder.Status,
Count(TblOrderShip.ShipDate) AS CountOfShipDate,
[CountOfShipDate]>0 AS [IsShipped?]
FROM TblOrder INNER JOIN TblOrderShip
ON TblOrder.OrderID = TblOrderShip.OrderID
GROUP BY TblOrder.OrderID, TblOrder.Status
HAVING (((Count(TblOrderShip.ShipDate)) Is Not Null))
ORDER BY TblOrder.OrderID;

[Q_Shipped Stuff] SQL:
SELECT [Q_Shipped?].OrderID, [Q_Shipped?].Status,
Q_Reasons.ReasonNotShipped
FROM [Q_Shipped?] INNER JOIN Q_Reasons
ON [Q_Shipped?].OrderID = Q_Reasons.OrderID
WHERE ((([Q_Shipped?].[IsShipped?])=No));

[Q_Shipped Stuff] Query Datasheet View:

OrderID Status ReasonNotShipped
---------- ------- ----------------
1945178752 Stalled Fungus


-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
G

Guest

Hi Vincent,

in testing this it seems to occur when the record source queries are
imported first and then the top/main query. The solution seems to be to
complete the loop in reverse order...

Interestingly, if I manually import these same queries it does not seem to
matter which order that I import them.


Thanks

Jonathan

Vincent Johns said:
Jonathan said:
Hi, I have a database that contains nested queries and I import these queries.

That is, the database contains queries that have queries as data source
(don't mean to dumb it down, just want the situation to be explicitly clear).
In the top query the source queries are joined on related fields.

The problem is that when I import (using DoCmd.TransferDatabase acImport)
all the queries involved, the joins are dropped. That is the source queries
still exist in the top query. However the joins between source queries no
longer exist.

Why is that? More importantly how can I avoid this happening?

I was unable to reproduce your problem. Perhaps some joined Table or
Query was missing, so Access blasted the links into oblivion; this would
be normal behavior.

If you want to try using my code, Tables, and Queries, maybe that will
shed light on your situation. (I omitted my usual error-checking code
from the VBA.) These procedures worked both when expressed as a Macro
and when defined using the following code:

'------------------------------------------------------------
' Import_Queries imports the specified Queries
' and the Tables on which they depend
'
'------------------------------------------------------------
Public Function ImportQueries()

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
Import1 acQuery, "Q_Reasons"

' Import [Q_Shipped Stuff]
Import1 acQuery, "Q_Shipped Stuff"

' Import [Q_Shipped?]
Import1 acQuery, "Q_Shipped?"

' Import [tblOrder]
Import1 acTable, "tblOrder"

' Import [tblOrderShip]
Import1 acTable, "tblOrderShip"

End Function 'ImportQueries()

'------------------------------------------------------------
' Import1() imports the specified object
'
'------------------------------------------------------------
Public Sub Import1( _
ByVal ObjectType As AcObjectType, _
ByVal ObjectName As String)

'ByVal ObjectType As AcObjectType 'acQuery _
or acTable
'ByVal ObjectName As String 'Name of Table _
or Query to import

Const strSourceFile As String = _
"c:\vrj\AccessHelp\db5K13a_Orders.mdb"

' Import [Q_Reasons]
DoCmd.TransferDatabase acImport, _
"Microsoft Access", _
strSourceFile, _
ObjectType, ObjectName, _
ObjectName, False

End Sub 'ImportQueries()

The (complete) contents of the two Tables are shown here:

[tblOrderShip] Table Datasheet View:

OrderShipID OrderID ShipDate ReasonNotShipped
----------- ----------- ---------- ----------------
-418235218 1945178752 Fungus
402604161 -1152314661 11/10/2005

[tblOrder] Table Datasheet View:

OrderID Status
----------- -------
-1152314661 Shipped
1945178752 Stalled

The three imported Queries are defined as follows; notice that
[Q_Shipped Stuff] includes a JOIN on [Q_Shipped?] and [Q_Reasons].

[Q_Reasons] SQL:
SELECT TblOrderShip.OrderID,
TblOrderShip.ReasonNotShipped
FROM TblOrderShip
ORDER BY TblOrderShip.ReasonNotShipped;

[Q_Shipped?] SQL:
SELECT TblOrder.OrderID, TblOrder.Status,
Count(TblOrderShip.ShipDate) AS CountOfShipDate,
[CountOfShipDate]>0 AS [IsShipped?]
FROM TblOrder INNER JOIN TblOrderShip
ON TblOrder.OrderID = TblOrderShip.OrderID
GROUP BY TblOrder.OrderID, TblOrder.Status
HAVING (((Count(TblOrderShip.ShipDate)) Is Not Null))
ORDER BY TblOrder.OrderID;

[Q_Shipped Stuff] SQL:
SELECT [Q_Shipped?].OrderID, [Q_Shipped?].Status,
Q_Reasons.ReasonNotShipped
FROM [Q_Shipped?] INNER JOIN Q_Reasons
ON [Q_Shipped?].OrderID = Q_Reasons.OrderID
WHERE ((([Q_Shipped?].[IsShipped?])=No));

[Q_Shipped Stuff] Query Datasheet View:

OrderID Status ReasonNotShipped
---------- ------- ----------------
1945178752 Stalled Fungus


-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 
V

Vincent Johns

Jonathan said:
Hi Vincent,

in testing this it seems to occur when the record source queries are
imported first and then the top/main query. The solution seems to be to
complete the loop in reverse order...

Interestingly, if I manually import these same queries it does not seem to
matter which order that I import them.

Thanks

Jonathan

Perhaps what's happening is that, after importing one of the Queries,
Access checks the links to determine if they are valid and erases the
ones that link to apparently-not-present fields (which you will import
later), and zaps the links as being invalid. Properties of a link
include the identifiers of the linked fields. However, since you had no
problem importing them manually (I assume in the same order), perhaps
something else is going on here. I suppose you could put a breakpoint
in your code and check the contents of the objects at various stages.

-- Vincent Johns <[email protected]>
Please feel free to quote anything I say here.
 

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