Field Name "RLEXT#" Causing ODBC Errors when Querying via DAO

M

Michael Koenig

Howdy!

I've got a real stumper here that I'm HOPING (praying...) that you all can
assist me with.

I'm building a database using a combination of SQL Server 2005 and AS-400
data files for the backend, and Access 97 as the frontend/UI. (Yes, I know...
please don't tease...)

As is often the case when dealing with legacy data, someone in the past
decided to use Chr(35) ("#") as a part of their field-naming convention when
creating an AS-400 data file without thinking of the needs of others. As a
result, I've got two fields that have this character in the field name, and
they're causing me pain.

I'm trying to create an on-the-fly ODBC pass-through query to look up data
pertaining to a specific account number that a user enters into my GUI, which
is something that I've done a thousand times before. The fields that have
this character (named RLEXT# and RLNEW#) work fine when I create a static
pass-through query using the SQL view of the Query Design Grid, using the SQL
string below:

SELECT CLPACMST.ACCTNO, CLPREFAL.RLEXT#, CLPACMST.APPLCT, CLPACMST.COAPPL,
CLPCUSTD.APPLCT AS Custodian, CLPHDOC.CUSTRF FROM (CLPCUSTD RIGHT JOIN
(CLPACMST LEFT JOIN CLPHDOC ON CLPACMST.ACCTNO = CLPHDOC.ACCTNO) ON
CLPCUSTD.CSTSEQ = CLPHDOC.CSTSEQ) LEFT JOIN CLPREFAL ON CLPACMST.ACCTNO =
CLPREFAL.RLNEW# WHERE (((CLPACMST.ACCTNO)=88098682))

However, because Access VBA likes to have it ITS way, when I try to
re-create the same SQL string in VBA as a part of a DAO recordset, I get the
following error:

"Run-time Error '3075': Syntax error in date in query expression
'CLPREFAL.RLEXT#'."

Now, I know that this is due to Access viewing the # as the start of a Date
string, so I know WHY it is happening... but can anyone offer a suggestion on
how to get around the issue? I can't get the field names changed, and I have
already tried to enclose the RLEXT# in brackets to no avail, so I'm at a
loss. If need be, I can pull the data fields from my AS-400 and rename them
at runtime, but the file has over 800,000 records in it, so I'd REALLY rather
not go there. Any other suggestions?

Thank you in advance - you all are real life savers to a geek in need! (Geek
being my AFFECTIONATE term for myself, and not an offensive label to be
applied to others!)
 
J

John Spencer

Did you try the following? Note the brackets go around the individual
parts of the table and field name and not around the entire name. That
is [CLPREFAL].[RLEXT#] and not [CLPREFAL.RLEXT#].

SELECT CLPACMST.ACCTNO
, [CLPREFAL].[RLEXT#]
, CLPACMST.APPLCT
, CLPACMST.COAPPL
, CLPCUSTD.APPLCT AS Custodian
, CLPHDOC.CUSTRF
FROM (CLPCUSTD RIGHT JOIN
(CLPACMST LEFT JOIN CLPHDOC
ON CLPACMST.ACCTNO = CLPHDOC.ACCTNO)
ON CLPCUSTD.CSTSEQ = CLPHDOC.CSTSEQ)
LEFT JOIN CLPREFAL
ON CLPACMST.ACCTNO = [CLPREFAL].[RLNEW#]
WHERE (((CLPACMST.ACCTNO)=88098682))

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
M

Michael Koenig

John,

Thank you for responding. Yes, I did try that, and I'm got a generic ODBC
error. In the past, when I've used brackets when querying our AS-400, I get
an invalid token error, so I am assuming that is the cause for the ODBC error.

Any other suggestions?
--
Michael



John Spencer said:
Did you try the following? Note the brackets go around the individual
parts of the table and field name and not around the entire name. That
is [CLPREFAL].[RLEXT#] and not [CLPREFAL.RLEXT#].

SELECT CLPACMST.ACCTNO
, [CLPREFAL].[RLEXT#]
, CLPACMST.APPLCT
, CLPACMST.COAPPL
, CLPCUSTD.APPLCT AS Custodian
, CLPHDOC.CUSTRF
FROM (CLPCUSTD RIGHT JOIN
(CLPACMST LEFT JOIN CLPHDOC
ON CLPACMST.ACCTNO = CLPHDOC.ACCTNO)
ON CLPCUSTD.CSTSEQ = CLPHDOC.CSTSEQ)
LEFT JOIN CLPREFAL
ON CLPACMST.ACCTNO = [CLPREFAL].[RLNEW#]
WHERE (((CLPACMST.ACCTNO)=88098682))

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Michael said:
Howdy!

I've got a real stumper here that I'm HOPING (praying...) that you all can
assist me with.

I'm building a database using a combination of SQL Server 2005 and AS-400
data files for the backend, and Access 97 as the frontend/UI. (Yes, I know...
please don't tease...)

As is often the case when dealing with legacy data, someone in the past
decided to use Chr(35) ("#") as a part of their field-naming convention when
creating an AS-400 data file without thinking of the needs of others. As a
result, I've got two fields that have this character in the field name, and
they're causing me pain.

I'm trying to create an on-the-fly ODBC pass-through query to look up data
pertaining to a specific account number that a user enters into my GUI, which
is something that I've done a thousand times before. The fields that have
this character (named RLEXT# and RLNEW#) work fine when I create a static
pass-through query using the SQL view of the Query Design Grid, using the SQL
string below:

SELECT CLPACMST.ACCTNO, CLPREFAL.RLEXT#, CLPACMST.APPLCT, CLPACMST.COAPPL,
CLPCUSTD.APPLCT AS Custodian, CLPHDOC.CUSTRF FROM (CLPCUSTD RIGHT JOIN
(CLPACMST LEFT JOIN CLPHDOC ON CLPACMST.ACCTNO = CLPHDOC.ACCTNO) ON
CLPCUSTD.CSTSEQ = CLPHDOC.CSTSEQ) LEFT JOIN CLPREFAL ON CLPACMST.ACCTNO =
CLPREFAL.RLNEW# WHERE (((CLPACMST.ACCTNO)=88098682))

However, because Access VBA likes to have it ITS way, when I try to
re-create the same SQL string in VBA as a part of a DAO recordset, I get the
following error:

"Run-time Error '3075': Syntax error in date in query expression
'CLPREFAL.RLEXT#'."

Now, I know that this is due to Access viewing the # as the start of a Date
string, so I know WHY it is happening... but can anyone offer a suggestion on
how to get around the issue? I can't get the field names changed, and I have
already tried to enclose the RLEXT# in brackets to no avail, so I'm at a
loss. If need be, I can pull the data fields from my AS-400 and rename them
at runtime, but the file has over 800,000 records in it, so I'd REALLY rather
not go there. Any other suggestions?

Thank you in advance - you all are real life savers to a geek in need! (Geek
being my AFFECTIONATE term for myself, and not an offensive label to be
applied to others!)
 

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