SunnyByfleet
Technical User
Odd one this.
Our company accountancy system is Swan. We have a Crystal Report that looks at three of the tables and joins them.
I am expanding on this with Access. I am using linked tables and querying them.
To speed up development, I have also exported the tables into native access. When I am developing the app, I point to the local tables, and when its live I will point to the live tables.
The three tables in question are:
For local:
L_SOR_TRANSACTIONS
L_SOR_SALES_ORDERS
L_SOR_COMPONENT_ALLOCS
For linked:
S_SOR_TRANSACTIONS
S_SOR_SALES_ORDERS
S_SOR_COMPONENT_ALLOCS
So to switch from local to linked, I just replave L_ with S_.
Pertinent fields in the tables are as follows:
SOR_SALES_ORDERS
---THIS.RECORD
---ORDER_NUMBER
SOR_TRANSACTIONS
---PARENT.RECORD
SOR_COMPONENT_ALLOCS
---ORDER_NUMBER
I haven't set up any explicit relationships. However, in the query I use inner joins:
SOR_SALES_ORDERS!THIS_RECORD = SOR_TRANSACTION!PARENT_RECORD
SOR_SALES_ORDERS!ORDER_NUMBER = SOR_COMPONENT_ALLOCS!ORDER_NUMBER
My problem is as follows, I have the query working fine when I point it to the local copy, but as soon as I point it to the linked tables I get an ODBC error:
Runtime error 3146.
ODBC -- call failed
I suspect it is the join causing the problem, in fact if I modify the query to have the SALES_ORDER table local and the other two link, then it works fine.
Where am I going wrong?
Here's the JOIN part of the query. Below it for completeness I've included the full query. In both cases, I am using the working code. To get the non-working code just change S_ to L_.
I'm going bald on this one, so all help is appreciated.
Our company accountancy system is Swan. We have a Crystal Report that looks at three of the tables and joins them.
I am expanding on this with Access. I am using linked tables and querying them.
To speed up development, I have also exported the tables into native access. When I am developing the app, I point to the local tables, and when its live I will point to the live tables.
The three tables in question are:
For local:
L_SOR_TRANSACTIONS
L_SOR_SALES_ORDERS
L_SOR_COMPONENT_ALLOCS
For linked:
S_SOR_TRANSACTIONS
S_SOR_SALES_ORDERS
S_SOR_COMPONENT_ALLOCS
So to switch from local to linked, I just replave L_ with S_.
Pertinent fields in the tables are as follows:
SOR_SALES_ORDERS
---THIS.RECORD
---ORDER_NUMBER
SOR_TRANSACTIONS
---PARENT.RECORD
SOR_COMPONENT_ALLOCS
---ORDER_NUMBER
I haven't set up any explicit relationships. However, in the query I use inner joins:
SOR_SALES_ORDERS!THIS_RECORD = SOR_TRANSACTION!PARENT_RECORD
SOR_SALES_ORDERS!ORDER_NUMBER = SOR_COMPONENT_ALLOCS!ORDER_NUMBER
My problem is as follows, I have the query working fine when I point it to the local copy, but as soon as I point it to the linked tables I get an ODBC error:
Runtime error 3146.
ODBC -- call failed
I suspect it is the join causing the problem, in fact if I modify the query to have the SALES_ORDER table local and the other two link, then it works fine.
Where am I going wrong?
Here's the JOIN part of the query. Below it for completeness I've included the full query. In both cases, I am using the working code. To get the non-working code just change S_ to L_.
I'm going bald on this one, so all help is appreciated.
Code:
cQuery = cQuery + "(L_SOR_SALES_ORDERS AS SOR_SALES_ORDERS INNER JOIN "
cQuery = cQuery + "S_SOR_TRANSACTIONS AS SOR_TRANSACTIONS ON "
cQuery = cQuery + "SOR_SALES_ORDERS.THIS_RECORD=SOR_TRANSACTIONS.PARENT_RECORD) "
cQuery = cQuery + "INNER JOIN S_SOR_COMPONENT_ALLOCS AS SOR_COMPONENT_ALLOCS ON "
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_NUMBER = SOR_COMPONENT_ALLOCS.ORDER_NUMBER "
Code:
cQuery = "SELECT "
cQuery = cQuery + "SOR_TRANSACTIONS.ITEM_NUMBER, "
cQuery = cQuery + "SOR_TRANSACTIONS.ITEM_DUE_DATE, "
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_NUMBER,"
cQuery = cQuery + "SOR_SALES_ORDERS.THEIR_REFERENCE,"
cQuery = cQuery + "SOR_SALES_ORDERS.ACCOUNT_NAME,"
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_DATE,"
cQuery = cQuery + "SOR_TRANSACTIONS.THIS_RECORD,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.COMPONENT_PART,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.NUMBER_OFF,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.QUANTITY_ORDERED,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.QUANTITY_ALLOCATED,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.QUANTITY_ISSUED,"
cQuery = cQuery + "SOR_COMPONENT_ALLOCS.PARENT_PART,"
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_DUE_DATE,"
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_STATUS"
cQuery = cQuery + " FROM "
cQuery = cQuery + "(L_SOR_SALES_ORDERS AS SOR_SALES_ORDERS INNER JOIN "
cQuery = cQuery + "S_SOR_TRANSACTIONS AS SOR_TRANSACTIONS ON "
cQuery = cQuery + "SOR_SALES_ORDERS.THIS_RECORD=SOR_TRANSACTIONS.PARENT_RECORD) "
cQuery = cQuery + "INNER JOIN S_SOR_COMPONENT_ALLOCS AS SOR_COMPONENT_ALLOCS ON "
cQuery = cQuery + "SOR_SALES_ORDERS.ORDER_NUMBER = SOR_COMPONENT_ALLOCS.ORDER_NUMBER "
cQuery = cQuery + "WHERE ("
cQuery = cQuery + "(SOR_SALES_ORDERS.THIS_RECORD = SOR_TRANSACTIONS.PARENT_RECORD) And "
cQuery = cQuery + "("
cQuery = cQuery + "("
cQuery = cQuery + "(SOR_SALES_ORDERS.ORDER_NUMBER=SOR_COMPONENT_ALLOCS.ORDER_NUMBER) AND "
cQuery = cQuery + "(SOR_TRANSACTIONS.ITEM_NUMBER=SOR_COMPONENT_ALLOCS.PARENT_PART)"
cQuery = cQuery + ")"
cQuery = cQuery + " AND "
cQuery = cQuery + "(SOR_TRANSACTIONS.SEQUENCE_NO=SOR_COMPONENT_ALLOCS.SEQUENCE_NO)"
cQuery = cQuery + ")"
cQuery = cQuery + " AND NOT "
cQuery = cQuery + "(SOR_SALES_ORDERS.ORDER_STATUS=0 OR SOR_SALES_ORDERS.ORDER_STATUS=9 OR SOR_SALES_ORDERS.ORDER_STATUS=10) and "
cQuery = cQuery + "SOR_TRANSACTIONS.ITEM_NUMBER=SOR_COMPONENT_ALLOCS.PARENT_PART And "
cQuery = cQuery + "((SOR_SALES_ORDERS.ORDER_DUE_DATE) <= #" & (AmericanFormat(Date + 30)) & "#)"
cQuery = cQuery + ")"
cQuery = cQuery + " ORDER BY SOR_TRANSACTIONS.ITEM_NUMBER, SOR_TRANSACTIONS.THIS_RECORD, SOR_TRANSACTIONS.ITEM_DUE_DATE;"