Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / April 2007

Tip: Looking for answers? Try searching our database.

Passing a Value to SQL from a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ross - 11 Apr 2007 16:16 GMT
Hi to All,

For: myName = “Jim”

I am storing  this SQL String:

Type A
STRSQL = "SELECT tblEmployees.Employee_ID, tblEmployees.First,
tblEmployees.Last, tblEmployees.Email "
STRSQL = STRSQL & "FROM tblEmployees "
STRSQL = STRSQL & "WHERE (((tblEmployees.First) = """ & MyName & """)) "
STRSQL = STRSQL & "ORDER BY tblEmployees.Last;"

In a Memo Field of a table as follows:
Type B
SELECT tblEmployees.Employee_ID, tblEmployees.First, tblEmployees.Last,
tblEmployees.Email
FROM tblEmployees
WHERE (((tblEmployees.First) = """ & MyName & """))
ORDER BY tblEmployees.Last;

If  I  create a qdf from Type A (and evaluate via (debug.print)) I get

WHERE (((tblEmployees.First) = "Jim"))

However:
If I retrieve the string from the Memo Field of the table (Type B) and
create a qdf from Type B (and evaluate via (debug.print)), I get

WHERE (((tblEmployees.First) = """ & MyName & """))

How can I set a variable, strsql, equal to the SQL string in the memo field
of a table,
And then create a querydef from the strsql  with “Jim” inserted into the sql
instead of  “”” & myName &  “”” ?

Thank You

Ross
Michel Walsh - 11 Apr 2007 16:50 GMT
You may get problem due to the memo field, in a query. Otherwise, you can
use DLookup or a JOIN to reach data from another table.

SELECT * FROM tableName WHERE fieldName = DLookup("otherField" ,
"otherTable", "someField=" & someParameter)

or

SELECT * FROM tableName INNER JOIN otherTable ON tableName.fieldName =
otherTable.otherField WHERE otherTable.someField = someParameter

are equivalent statements  *IF*  there is just one row where:

       otherTable.someField = someParameter

is true.

Vanderghast, Access MVP

> Hi to All,
>
[quoted text clipped - 37 lines]
>
> Ross
Ross - 11 Apr 2007 20:16 GMT
Thanks Michel,

I will ponder these things!

> You may get problem due to the memo field, in a query. Otherwise, you can
> use DLookup or a JOIN to reach data from another table.
[quoted text clipped - 56 lines]
> >
> > Ross
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.