Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP syntax when Access field has # 1

Status
Not open for further replies.

riley3

Programmer
Apr 29, 2004
79
US
Hello,
I'm trying to read an Access database that has a field named "Contract#" using an ASP coded web page but keep getting a syntax error. This is a database associated with a purchased application so we don't have control over the naming conventions. Is there some way this field can be read with ASP even with the special character?
Thanks, Riley
 
Use square brackets around the field name in your queries.

Ex:

Code:
Select [!][[/!]Contract#[!]][/!], Field2
From   TableName

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for the help - worked just fine. Riley
 
I may have spoke to soon. I got rid of one error message but now there is a new one. I've been looking at it for a while but can't see the error.
===================================
strSQL = "SELECT [tblContractCustomers.Contract#] AS cno, "
strSQL = strSQL & "tblContractCustomers.AccountNumber AS cacctno, "
strSQL = strSQL & "tblContracts.Description AS cdesc, "
strSQL = strSQL & "tblContracts.DateWritten AS datewritten, "
strSQL = strSQL & "tblContracts.StartDate AS startdate, "
strSQL = strSQL & "tblContracts.ExpirationDate AS expdate, "
strSQL = strSQL & "tblContracts.ContractHours AS chours, "
strSQL = strSQL & "tblContracts.ContractMinutes AS cmin, "
strSQL = strSQL & "tblContracts.HoursRemaining AS hremain, "
strSQL = strSQL & "tblContracts.MinutesRemaining AS mremain, "
strSQL = strSQL & "tblAccounts.AccountNumber AS anum, "
strSQL = strSQL & "tblAccounts.AccountName As cust "

strSQL = strSQL & "FROM tblAccounts INNER JOIN ( tblContractCustomers "
strSQL = strSQL & "INNER JOIN tblContracts "
strSQL = strSQL & "ON [tblContractCustomers.Contract#] = tblContracts.ContractNumber ) "
strSQL = strSQL & "ON tblAccounts.AccountNumber = tblContractCustomers.AccountNumber "
strSQL = strSQL & "WHERE tblContracts.HoursRemaining > '" & strZero & "' "
strSQL = strSQL & "OR tblContracts.MinutesRemaining > '" & strZero & "' "
strSQL = strSQL & "ORDER BY tblContracts.ContractNumber DESC "
==============================
The error is - Invalid bracketing of name '[tblContractCustomers.Contract#]'.
- it's in the ON statement but I can't see a problem. Thanks for any additional help you may be able to give me.
Riley
 
[tblContractCustomers.Contract#] is wrong.

Use:

tblContractCustomers.[!][[/!]Contract#[!]][/!]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That did it. The error in question went away. I still have an error, unrelated. It's a "mismatch" error and a different problem. I have these all the time and will deal with it later. Thanks again for the help.
Riley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top