SQL Error Please help

SQL Error Please help

Anonymous
Not applicable
712 Views
8 Replies
Message 1 of 9

SQL Error Please help

Anonymous
Not applicable
I have an ADO connection to a MDB. I can open my tables. But when I try
and run query on table I keep getting error. I have attach some of the code
in event someone can help me with statement.

ptdesc = "any string"
curconn.Open CurrentProject.Connection
sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
(((Codes.Code)= ptdesc));"
RSCode.Open sqlstmt, curconn, adOpenDynamic, adLockOptimistic,-1

The fields in the table are all strings. I think error is in the -1, VBA
show this as an option. But says -1 is LONG. I don't know what string is,
but I don't know if this is the problem or not.
0 Likes
713 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
William Salling wrote:

> ptdesc = "any string"

Here, 'ptdesc' is a variable with the value "any string".

> sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> (((Codes.Code)= ptdesc));"

Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
value of the variable you set earlier, you must concatentate the query
string and the variable.

sqlstmt = "yada yada " & ptdesc & " more yada yada"

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
0 Likes
Message 3 of 9

Anonymous
Not applicable
In addition to that, the sql will require quotes around the string value:
value="some string". Since a double quote is a delimiter for a string
variable, you need to use a control character when concatenating. When you
concat to include a double quote: sqlstmt="some sql WHERE value=""" &
varvalue & """

--
Ed
--

"Frank Oquendo" wrote in message
news:[email protected]...
> William Salling wrote:
>
> > ptdesc = "any string"
>
> Here, 'ptdesc' is a variable with the value "any string".
>
> > sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> > (((Codes.Code)= ptdesc));"
>
> Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
> value of the variable you set earlier, you must concatentate the query
> string and the variable.
>
> sqlstmt = "yada yada " & ptdesc & " more yada yada"
>
> --
> There are 10 kinds of people. Those who understand binary and those who
> don't.
>
> http://code.acadx.com
>
>
0 Likes
Message 4 of 9

Anonymous
Not applicable
I rewrote the statement like this.

sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
(((Codes.Code)=" & ptdesc & "))" & ";"
ptdesc is a attribute of text. Do I still need to put extra quotes?



"Ed Jobe" wrote in message
news:[email protected]...
> In addition to that, the sql will require quotes around the string value:
> value="some string". Since a double quote is a delimiter for a string
> variable, you need to use a control character when concatenating. When you
> concat to include a double quote: sqlstmt="some sql WHERE value=""" &
> varvalue & """
>
> --
> Ed
> --
>
> "Frank Oquendo" wrote in message
> news:[email protected]...
> > William Salling wrote:
> >
> > > ptdesc = "any string"
> >
> > Here, 'ptdesc' is a variable with the value "any string".
> >
> > > sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> > > (((Codes.Code)= ptdesc));"
> >
> > Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
> > value of the variable you set earlier, you must concatentate the query
> > string and the variable.
> >
> > sqlstmt = "yada yada " & ptdesc & " more yada yada"
> >
> > --
> > There are 10 kinds of people. Those who understand binary and those who
> > don't.
> >
> > http://code.acadx.com
> >
> >
>
>
0 Likes
Message 5 of 9

Anonymous
Not applicable
Thanks guys. The double quote worked great.


thanks again.


"William Salling" wrote in message
news:[email protected]...
> I rewrote the statement like this.
>
> sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> (((Codes.Code)=" & ptdesc & "))" & ";"
> ptdesc is a attribute of text. Do I still need to put extra quotes?
>
>
>
> "Ed Jobe" wrote in message
> news:[email protected]...
> > In addition to that, the sql will require quotes around the string
value:
> > value="some string". Since a double quote is a delimiter for a string
> > variable, you need to use a control character when concatenating. When
you
> > concat to include a double quote: sqlstmt="some sql WHERE value=""" &
> > varvalue & """
> >
> > --
> > Ed
> > --
> >
> > "Frank Oquendo" wrote in message
> > news:[email protected]...
> > > William Salling wrote:
> > >
> > > > ptdesc = "any string"
> > >
> > > Here, 'ptdesc' is a variable with the value "any string".
> > >
> > > > sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> > > > (((Codes.Code)= ptdesc));"
> > >
> > > Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
> > > value of the variable you set earlier, you must concatentate the query
> > > string and the variable.
> > >
> > > sqlstmt = "yada yada " & ptdesc & " more yada yada"
> > >
> > > --
> > > There are 10 kinds of people. Those who understand binary and those
who
> > > don't.
> > >
> > > http://code.acadx.com
> > >
> > >
> >
> >
>
>
0 Likes
Message 6 of 9

Anonymous
Not applicable
Ed Jobe wrote:
> In addition to that, the sql will require quotes around the string
> value: value="some string".

Good catch. One thing I like to do is use single quotes so as not to
deal with trying to remember just how many double quotes to include:

sqlstmt = " yada yada WHERE blah='" & someVariable & "'"

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
0 Likes
Message 7 of 9

Anonymous
Not applicable
I'm surprised that double quotes work; in SQL, single quote is the string
delimiter and double quote is the identifier delimiter (required for
non-regular identifiers such as column names that contain spaces). Double
quotes around strings do work with Access databases under certain conditions
(because of Access's non-standard dialect of SQL) but I am pretty sure they
don't work in all cases.

--
jrf
Member of the Autodesk Discussion Forum Moderator Program
Please do not email questions unless you wish to hire my services

In article , Ed Jobe
wrote:
> In addition to that, the sql will require quotes around the string value:
> value="some string". Since a double quote is a delimiter for a string
> variable, you need to use a control character when concatenating. When you
> concat to include a double quote: sqlstmt="some sql WHERE value=""" &
> varvalue & """
>
> --
> Ed
> --
>
> "Frank Oquendo" wrote in message
> news:[email protected]...
> > William Salling wrote:
> >
> > > ptdesc = "any string"
> >
> > Here, 'ptdesc' is a variable with the value "any string".
> >
> > > sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> > > (((Codes.Code)= ptdesc));"
> >
> > Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
> > value of the variable you set earlier, you must concatentate the query
> > string and the variable.
> >
> > sqlstmt = "yada yada " & ptdesc & " more yada yada"
> >
> > --
> > There are 10 kinds of people. Those who understand binary and those who
> > don't.
> >
> > http://code.acadx.com
> >
> >
>
0 Likes
Message 8 of 9

Anonymous
Not applicable
I had to use the ascii code for the quotes.


"Jon Fleming" wrote in message
news:[email protected]...
> I'm surprised that double quotes work; in SQL, single quote is the string
> delimiter and double quote is the identifier delimiter (required for
> non-regular identifiers such as column names that contain spaces). Double
> quotes around strings do work with Access databases under certain
conditions
> (because of Access's non-standard dialect of SQL) but I am pretty sure
they
> don't work in all cases.
>
> --
> jrf
> Member of the Autodesk Discussion Forum Moderator Program
> Please do not email questions unless you wish to hire my services
>
> In article , Ed Jobe
> wrote:
> > In addition to that, the sql will require quotes around the string
value:
> > value="some string". Since a double quote is a delimiter for a string
> > variable, you need to use a control character when concatenating. When
you
> > concat to include a double quote: sqlstmt="some sql WHERE value=""" &
> > varvalue & """
> >
> > --
> > Ed
> > --
> >
> > "Frank Oquendo" wrote in message
> > news:[email protected]...
> > > William Salling wrote:
> > >
> > > > ptdesc = "any string"
> > >
> > > Here, 'ptdesc' is a variable with the value "any string".
> > >
> > > > sqlstmt = "SELECT Codes.Code, Codes.Description FROM Codes WHERE
> > > > (((Codes.Code)= ptdesc));"
> > >
> > > Here, 'ptdesc' is a string with the value "ptdesc". To incorporate the
> > > value of the variable you set earlier, you must concatentate the query
> > > string and the variable.
> > >
> > > sqlstmt = "yada yada " & ptdesc & " more yada yada"
> > >
> > > --
> > > There are 10 kinds of people. Those who understand binary and those
who
> > > don't.
> > >
> > > http://code.acadx.com
> > >
> > >
> >
>
>
0 Likes
Message 9 of 9

Anonymous
Not applicable
I just use a
Public Const QUOTE = """"


Then in code use something like

"Where BOMNO=" & QUOTE & BOMNumber & QUOTE

Joe
0 Likes