|
 |
access thread: Assigning SELECT result to a string
Message #1 by "Nigel Green" <nigelgreenx2@n...> on Thu, 30 Jan 2003 11:10:10
|
|
Whenever I try to assign a SELECT statement to a string the string only
ever takes the value of the SELECT statement itself
e.g.
Dim strQuery as String
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID] = Me!
ElementName]"
then strQuery gets the value "SELECT * FROM [tblElementName]WHERE
[tblElementName].[ID] = Me!ElementName]"
What am I doing wrong. (The Select statement may be wrong but that's
another problem)
Message #2 by "Steven White" <Steve.White@m...> on Thu, 30 Jan 2003 11:48:54
|
|
What did you WANT the string value to be?
going by the code you've got there - it looks like it's working perfectly
Of course - if you want to actually RUN some sql, then you'll have to use
either
CurrentDB.Execute
or
DoCmd.RunSQL
(both of these commands only work on action statements, eg: Insert,
Delete)
but why you'd want to just run a SELECT statement is a whole different
animal.
If you gave some more info on what you're actually trying to accomplish,
it would be easier to help you
Steven
Message #3 by Adriane.Delvillar@a... on Thu, 30 Jan 2003 19:42:13 +0800
|
|
TRY THIS,
Dim cn as ADODB.Connection
Dim rsQuery as ADODB.Recordset
Dim strQuery as String
Dim V as String
Set cn = CurrentProject.Connection
Set rsQuery = new ADODB.Recordset
strQuery = "SELECT * FROM [tblElementName]WHERE [ID]=" & ME![ElementName]
rsQuery.Open StrQuery, cn
'If you want to get the value of ID.
'Depends on which row you want.
V = rsQuery.Fields(ID).Value
Best Regards!
>>>-- ian -->>
"Nigel Green" <nigelgreenx2@n...>
01/30/2003 07:10 PM
Please respond to "Access"
To: "Access" <access@p...>
cc:
Subject: [access] Assigning SELECT result to a string
Whenever I try to assign a SELECT statement to a string the string only
ever takes the value of the SELECT statement itself
e.g.
Dim strQuery as String
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID] =
Me!
ElementName]"
then strQuery gets the value "SELECT * FROM [tblElementName]WHERE
[tblElementName].[ID] = Me!ElementName]"
What am I doing wrong. (The Select statement may be wrong but that's
another problem)
Message #4 by "John Fejsa" <John.Fejsa@h...> on Fri, 31 Jan 2003 08:25:01 +1100
|
|
Try
Dim strQuery as String
'Use this if Me!ElementName is a a numeric
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID]
" & Me!ElementName & ";"
'Use this if Me!ElementName is a string - notice quotes "'" enclosing
the ElementName value
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID]
'" & Me!ElementName & "';"
Hope that's of some help.
____________________________________________________
John Fejsa
Systems Analyst/Computer Programmer
Hunter Centre for Health Advancement
Locked Bag 10, WALLSEND NSW 2287
Phone: (02) 4924 6336 Fax: (02) 4924 6209
www.hcha.org.au
____________________________________________________
The doors we open and close each day decide the lives we live
____________________________________________________
CONFIDENTIALITY & PRIVILEGE NOTICE
>>> nigelgreenx2@n... 30/01/2003 22:10:10 >>>
Whenever I try to assign a SELECT statement to a string the string only
ever takes the value of the SELECT statement itself
e.g.
Dim strQuery as String
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID]
Me!
ElementName]"
then strQuery gets the value "SELECT * FROM [tblElementName]WHERE
[tblElementName].[ID] = Me!ElementName]"
What am I doing wrong. (The Select statement may be wrong but that's
another problem)
This message is intended for the addressee named
and may contain confidential information.
If you are not the intended recipient, please
delete it and notify the sender.
Views expressed in this message are those of the
individual sender, and are not necessarily the
views of Hunter Health.
Message #5 by "cdebiasio@t... on Fri, 31 Jan 2003 14:09:18 +0100 (CET)
|
|
Hi!!!
First of all, what do you want to obtain? I mean, what are you trying to store
in the string and why?
Just let me know, so we can solve it!
Claudio de Biasio
Team 97 S.r.l.
Quoting Nigel Green <nigelgreenx2@n...>:
> Whenever I try to assign a SELECT statement to a string the string only
>
> ever takes the value of the SELECT statement itself
>
> e.g.
> Dim strQuery as String
> strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID]
> Me!
> ElementName]"
>
> then strQuery gets the value "SELECT * FROM [tblElementName]WHERE
> [tblElementName].[ID] = Me!ElementName]"
>
> What am I doing wrong. (The Select statement may be wrong but that's
> another problem)
>
Message #6 by "Nigel Green" <nigelgreenx2@n...> on Fri, 31 Jan 2003 16:06:23
|
|
Thanks. That looks useful but I will confirm it by explaining what I want
to do.
The table asssociated with my form stores a number for the selected combo
item,(ElementName) not the value. The actual value of the combo is stored
in tblElementName.
I want to retreive the string from tblElemntName for use in a report or
some other use. tblProperties and tblElementName have a 1 to many
relationship linked by their ID. So I reckon Ian's suggestion should do.
Can you confirm. I guess that tblProperties.ElementName needn't have a
number but I can't remember what I did to make it do that. It used to
store the value.
Thanks Nigel
> TRY THIS,
Dim cn as ADODB.Connection
Dim rsQuery as ADODB.Recordset
Dim strQuery as String
Dim V as String
Set cn = CurrentProject.Connection
Set rsQuery = new ADODB.Recordset
strQuery = "SELECT * FROM [tblElementName]WHERE [ID]=" & ME![ElementName]
rsQuery.Open StrQuery, cn
'If you want to get the value of ID.
'Depends on which row you want.
V = rsQuery.Fields(ID).Value
Best Regards!
>>>-- ian -->>
"Nigel Green" <nigelgreenx2@n...>
01/30/2003 07:10 PM
Please respond to "Access"
To: "Access" <access@p...>
cc:
Subject: [access] Assigning SELECT result to a string
Whenever I try to assign a SELECT statement to a string the string only
ever takes the value of the SELECT statement itself
e.g.
Dim strQuery as String
strQuery = "SELECT * FROM [tblElementName]WHERE [tblElementName].[ID] =
Me!
ElementName]"
then strQuery gets the value "SELECT * FROM [tblElementName]WHERE
[tblElementName].[ID] = Me!ElementName]"
What am I doing wrong. (The Select statement may be wrong but that's
another problem)
|
|
 |