473,385 Members | 1,693 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,385 software developers and data experts.

Need help with pass-thru and local queries

Tcs
I've been stumped on this for quite a while. I don't know if it's so simple
that I just can't see it, or it's really possible. (Obviously, I HOPE it IS
possible.)

I'm trying to get my queries to run from VB. My pass-thru query retrieves
data from our AS/400 that I use to build a local table (on my PC). My pass-thru
and local do in fact work together when I run them interactively. But I want,
no make that NEED, to run them from VB.

Here's the code that Access built for the local query:

INSERT INTO tblAcctsRecAging_Details
( CustID,
LocID,
CustClass,
Serv,
PeriodYear,
PeriodMonth,
AgeCode,
ChgType,
ChgDesc,
90dayAmtBilled,
90dayUnpaid )

SELECT
qryAcctsRecAging_0040_90days_420_BE.UTCSID,
qryAcctsRecAging_0040_90days_420_BE.UTLCID,
qryAcctsRecAging_0040_90days_420_BE.UTRCLS,
qryAcctsRecAging_0040_90days_420_BE.UTSVC,
qryAcctsRecAging_0040_90days_420_BE.UTPEYY,
qryAcctsRecAging_0040_90days_420_BE.UTPEMM,
qryAcctsRecAging_0040_90days_420_BE.UTAGE,
qryAcctsRecAging_0040_90days_420_BE.UTTTYP,
qryAcctsRecAging_0040_90days_420_BE.UTTDSC,
qryAcctsRecAging_0040_90days_420_BE.UTTAMT,
qryAcctsRecAging_0040_90days_420_BE.UTUNPD

FROM tblAcctsRecAging_Details
RIGHT JOIN qryAcctsRecAging_0040_90days_420_BE
ON tblAcctsRecAging_Details.LocID =
qryAcctsRecAging_0040_90days_420_BE.UTLCID;

(Please don't tell me that my (BE) pass-thru query name is too long. While that
may be true, the fact of the matter is...it WORKS.)

Here's my pass-thru (qryAcctsRecAging_0040_90days_420_BE) query:

SELECT distinct
b.UTCSID,
b.UTLCID,
b.UTRCLS,
b.UTSVC,
b.UTPEYY,
b.UTPEMM,
b.UTAGE,
b.UTTTYP,
b.UTTDSC,
b.UTTAMT,
b.UTUNPD

FROM tblCXLIB.UT420AP as b

WHERE
((b.UTAGE='C') AND
(((b.UTPEMM)=8) AND ((b.UTPEYY)=4)) Or
(((b.UTPEMM)=7) AND ((b.UTPEYY)=4)))

ORDER BY
b.UTRCLS,
b.UTSVC,
b.UTPEYY,
b.UTPEMM,
b.UTTTYP,
b.UTTDSC;

I have modified the local query to:

INSERT INTO tblAcctsRecAging_Details
( CustID,
LocID,
CustClass,
Serv,
PeriodYear,
PeriodMonth,
AgeCode,
ChgType,
ChgDesc,
90dayAmtBilled,
90dayUnpaid )

SELECT
UTCSID,
UTLCID,
UTRCLS,
UTSVC,
UTPEYY,
UTPEMM,
UTAGE,
UTTTYP,
UTTDSC,
UTTAMT,
UTUNPD

FROM tblAcctsRecAging_Details
RIGHT JOIN (<my pass-thru "BE" query>)
ON tblAcctsRecAging_Details.LocID = tblCXLIB_UT420AP.[UTLCID];

BUT...I'm getting an error #3131 message of "Syntax error in FROM clause". I
feel that I'm getting closer, but I still haven't gotten it quite "right". I've
tried varaiations of this FROM clause, but to no avail.

Can anyone help? Have any thoughts/suggestions?

Thanks in advance.

Nov 13 '05 #1
8 2588
Tcs wrote:
I've been stumped on this for quite a while. I don't know if it's so
simple
that I just can't see it, or it's really possible. (Obviously, I HOPE it
IS possible.)

I'm trying to get my queries to run from VB. My pass-thru query retrieves
data from our AS/400 that I use to build a local table (on my PC). My
pass-thru
and local do in fact work together when I run them interactively. But I
want, no make that NEED, to run them from VB.
<Snipped Queries>
BUT...I'm getting an error #3131 message of "Syntax error in FROM clause".
I
feel that I'm getting closer, but I still haven't gotten it quite "right".
I've tried varaiations of this FROM clause, but to no avail.

Can anyone help? Have any thoughts/suggestions?

Thanks in advance.


Okay, we got the queries, obviously they've been saved. (Right?) You didn't
show us the code in question that runs these queries, but it should be
just:
docmd.openquery "<Insert Local Query Name Here>"

If your saved Local Query runs, this will run.

Also, looking through this carefully, your modified local query probably
doesn't know about the table tblCXLIB_UT420AP. It only knows about your
<my pass-thru "BE" query>, as you put it. You should probaly change that
to qryAcctsRecAging_0040_90days_420_BE from your previous query. Double
check your right join on statement.
--
Christopher Lewis
Nov 13 '05 #2
Tcs
On Wed, 01 Sep 2004 00:33:56 -0500, Christopher Lewis <ch******@cox.net> wrote:
Tcs wrote:
I've been stumped on this for quite a while. I don't know if it's so
simple
that I just can't see it, or it's really possible. (Obviously, I HOPE it
IS possible.)

I'm trying to get my queries to run from VB. My pass-thru query retrieves
data from our AS/400 that I use to build a local table (on my PC). My
pass-thru
and local do in fact work together when I run them interactively. But I
want, no make that NEED, to run them from VB.
<Snipped Queries>
BUT...I'm getting an error #3131 message of "Syntax error in FROM clause".
I
feel that I'm getting closer, but I still haven't gotten it quite "right".
I've tried varaiations of this FROM clause, but to no avail.

Can anyone help? Have any thoughts/suggestions?

Thanks in advance.


Okay, we got the queries, obviously they've been saved. (Right?) You didn't
show us the code in question that runs these queries, but it should be
just:
docmd.openquery "<Insert Local Query Name Here>"


If I just wanted to run the saved queries, then yes, this is what I would do.
(And have done so elsewhere.) But I don't just want to run the saved queries.
The parameters are variable. So I build my SQL statements in VB. (I've looked
at them, VB has built what I have told it to build.) So in THIS case, I use the
DoCmd.RunSQL statement, using my built statements. THIS...is what I can't get
to work. My assumption being is that my syntax is incorrect somehow.
If your saved Local Query runs, this will run.

Also, looking through this carefully, your modified local query probably
doesn't know about the table tblCXLIB_UT420AP. It only knows about your
<my pass-thru "BE" query>, as you put it.
Actually, tblCXLIB_UT420AP is a linked table to the AS/400. Access hasn't had a
problem with it before.
You should probaly change that
to qryAcctsRecAging_0040_90days_420_BE from your previous query.
I've tried that. It doesn't work.
Double check your right join on statement.


It's what Access used. It sounds right, it seems right, I just don't know if I
got the syntax right.

MAYBE...MAYBE my problem is more fundamental...

Perhaps when using the DoCmd.RunSQL command, Access doesn't know that the
pass-thru query, is in fact, a pass-thru query. Maybe it's trying to run it
locally. Hmmm...if this is true, then how WOULD I run a pass-thru query using
this command?


Nov 13 '05 #3
"Tcs" <ts****@eastpointcity.org> wrote in message
news:e9********************************@4ax.com...
On Wed, 01 Sep 2004 00:33:56 -0500, Christopher Lewis <ch******@cox.net> wrote:
MAYBE...MAYBE my problem is more fundamental...

Perhaps when using the DoCmd.RunSQL command, Access doesn't know that the
pass-thru query, is in fact, a pass-thru query. Maybe it's trying to run it locally. Hmmm...if this is true, then how WOULD I run a pass-thru query using this command?


Bingo! DoCmd.RunSQL assumes a local query. I don't think it can be used
for a pass-thru. You could define a saved Query with the proper pass-thru
settings for Connect, etc., and then modify the SQL of that query using
your code and then execute the saved query. I do this all the time.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Nov 13 '05 #4
Tcs
On Wed, 1 Sep 2004 13:10:10 -0500, "Rick Brandt" <ri*********@hotmail.com>
wrote:
"Tcs" <ts****@eastpointcity.org> wrote in message
news:e9********************************@4ax.com.. .
On Wed, 01 Sep 2004 00:33:56 -0500, Christopher Lewis <ch******@cox.net>

wrote:

MAYBE...MAYBE my problem is more fundamental...

Perhaps when using the DoCmd.RunSQL command, Access doesn't know that the
pass-thru query, is in fact, a pass-thru query. Maybe it's trying to run

it
locally. Hmmm...if this is true, then how WOULD I run a pass-thru query

using
this command?


Bingo! DoCmd.RunSQL assumes a local query. I don't think it can be used
for a pass-thru. You could define a saved Query with the proper pass-thru
settings for Connect, etc., and then modify the SQL of that query using
your code and then execute the saved query. I do this all the time.


Okay. You're saying I'd actually 'run' my saved query with the DoCmd.OpenQuery
command, which should work, since my queries work interactively. But I would
programatically CHANGE my saved query before doing so? How would I do that?
Could you provide an example?

Thanks!

Nov 13 '05 #5
"Tcs" <ts****@eastpointcity.org> wrote in message
news:51********************************@4ax.com...
On Wed, 1 Sep 2004 13:10:10 -0500, "Rick Brandt" <ri*********@hotmail.com> wrote: Okay. You're saying I'd actually 'run' my saved query with the DoCmd.OpenQuery command, which should work, since my queries work interactively. But I would programatically CHANGE my saved query before doing so? How would I do that? Could you provide an example?


CurrentDB.QueryDefs("QueryName").SQL = strNewSQL
CurrentDB.Execute "QueryName", dbFailOnError

(I never use DoCmd.OpenQuery)
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #6
Tcs
On Wed, 1 Sep 2004 15:35:54 -0500, "Rick Brandt" <ri*********@hotmail.com>
wrote:
"Tcs" <ts****@eastpointcity.org> wrote in message
news:51********************************@4ax.com.. .
On Wed, 1 Sep 2004 13:10:10 -0500, "Rick Brandt"

<ri*********@hotmail.com>
wrote:

Okay. You're saying I'd actually 'run' my saved query with the

DoCmd.OpenQuery
command, which should work, since my queries work interactively. But I

would
programatically CHANGE my saved query before doing so? How would I do

that?
Could you provide an example?


CurrentDB.QueryDefs("QueryName").SQL = strNewSQL
CurrentDB.Execute "QueryName", dbFailOnError

(I never use DoCmd.OpenQuery)


Wow. I haven't had time to do everything that I need to do...yet, but I DID
modify the contents of my query, by using the command you said to use. WOW. It
works. And it's so...so...simple.

Now, another question, or two, if I may. Does the '.SQL' imply that it's a
pass-thru query? (What DOES the '.SQL' mean?) Would I use:

CurrentDB.CreateQueryDef("QueryName").SQL = strNewSQL

if my query didn't exist?

Thank you, thank you, thank you!
Nov 13 '05 #7

"Tcs" <ts****@eastpointcity.org> wrote in message
news:qf********************************@4ax.com...

Wow. I haven't had time to do everything that I need to do...yet, but I DID
modify the contents of my query, by using the command you said to use. WOW. It works. And it's so...so...simple.

Now, another question, or two, if I may. Does the '.SQL' imply that it's a
pass-thru query? (What DOES the '.SQL' mean?) Would I use:
The SQL propery simply contains the SQL statement for the query. The graphical
query design grid is merely a tool for letting Access create the SQL in the
background. You can go into SQL view for any query to look at the statement.
The command I gave you sinply allows you to change the SQL statement from code.

It is the Connect property that specifies that a query is a Pass-thru.
Non-Pass-Thrus will have no Connect property while Pass-Thrus will.

Would I use:
CurrentDB.CreateQueryDef("QueryName").SQL = strNewSQL
if my query didn't exist?


It's a bit more than that. CreateQueryDef would create an in-memory QueryDef
object and then you would need to append that to the database's QueryDefs
collection to make it permanent. If you look at the help file for
CreateQueryDef you will see examples of its usage.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #8
Tcs
On Wed, 1 Sep 2004 19:09:42 -0500, "Rick Brandt" <ri*********@hotmail.com>
wrote:

"Tcs" <ts****@eastpointcity.org> wrote in message
news:qf********************************@4ax.com.. .

Wow. I haven't had time to do everything that I need to do...yet, but I DID
modify the contents of my query, by using the command you said to use. WOW.

It
works. And it's so...so...simple.

Now, another question, or two, if I may. Does the '.SQL' imply that it's a
pass-thru query? (What DOES the '.SQL' mean?) Would I use:


The SQL propery simply contains the SQL statement for the query. The graphical
query design grid is merely a tool for letting Access create the SQL in the
background. You can go into SQL view for any query to look at the statement.
The command I gave you sinply allows you to change the SQL statement from code.

It is the Connect property that specifies that a query is a Pass-thru.
Non-Pass-Thrus will have no Connect property while Pass-Thrus will.

Would I use:
CurrentDB.CreateQueryDef("QueryName").SQL = strNewSQL
if my query didn't exist?


It's a bit more than that. CreateQueryDef would create an in-memory QueryDef
object and then you would need to append that to the database's QueryDefs
collection to make it permanent. If you look at the help file for
CreateQueryDef you will see examples of its usage.


Thank you....VERY much!
Nov 13 '05 #9

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

Similar topics

11
by: rigga | last post by:
Hi, I am trying to code a menu for a webpage, the menu is broken up to groups i.e: Home Group1  menuitem1  menuitem2  menuitem3
7
by: pmatos | last post by:
Hi all, I've been having questions about strings, references, initializations... I've created code (which will not compile due to a reference problem) and I'd like comments on why this won't...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
4
by: Bob | last post by:
Hallo, I have to make a web application in Javascript/ASP for tenniscourt reservation (based on Access database). I would like to do everything with one page, because the user must be able to...
2
by: Vagabond | last post by:
I am trying to write a PHP script for tracking information and storing it in text files. The program has gotten to the point that I now need several php pages for the program to work however I can't...
8
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't...
10
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.