You cannot implement the [CREATE PROCEDURE] code you posted in the other thread ... in
a simple ACCESS query!
The SQL to create the PROC can be run in the Access user interface
when in ANSI-92 Query Mode; it can also be run in 'traditional'
ANSI-89 Query Mode by altering from:
CREATE PROCEDURE GetCustomersFromList
(
delimted_text MEMO,
delimiter VARCHAR(4) = ','
)
AS
SELECT ...
to (aircode):
PARAMETERS delimted_text MEMO, delimiter VARCHAR(4);
SELECT...
and manually saving the Query object as 'GetCustomersFromList';
however, I'm not sure whether the revised syntax fully supports
default parameter values.
You cannot implement the ... VBA,
I didn't post any VBA. Do you must mean my description of a possible
'procedural' approach. If so, what do you think is not achievable
using VBA? Parsing a delimited string? Putting values in a table?
Invoking a query?
One problem I have is that "ACCESS query" could mean many things. I
reserve 'query' for a SQL DML SELECT that returns a resultset,
anything else being a SQL *statement*; phrases such as 'delete query'
are contradictory for me. Sometimes 'query' is used here to mean an
object stored in the mdb, that which I'd call either a VIEW or a
PROCEDURE (depending on whether the resultset can be used as a virtual
table); these more specific terms have been around in Access/Jet SQL
syntax for nearly a decade now: OK SQL-92 Query Mode isn't the
'traditional' mode but has been the default since at least Access
2003. 'Access' sometimes means just the user interface, sometimes it
means just the engine. Sometimes 'Access' is used loosely by intent,
other times the originator is being vague because they can't tell the
interface from the engine.
What do *you* mean by "ACCESS query"?
The OP indicated that the he is typing text into an inputbox (Parameter)
when his query is run.
A PROC defined at the engine level using CREATE PROCEDURE or
PARAMETERS syntax can by invoked in that way in the Access user
interface.
Why do you insist on confusing the issue.
A little self doubt can take you a long way; perhaps it is you who is
confused
Here's a suggestion: try getting my example running in Northwind.
Perhaps it will clarify a few things for you. Here's some VBA to
create a new mdb with the tables, data and parameter query for you to
to see it working (and perhaps examine in the Access user interface):
Sub ParseDelimitedCustomers()
Kill Environ$("temp") & "\DropMe.mdb"
Dim cat
Set cat = CreateObject("ADOX.Catalog")
With cat
..Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Environ$("temp") & "\DropMe.mdb"
With .ActiveConnection
Dim sql As String
sql = _
"CREATE TABLE Sequence (seq INTEGER" & _
" PRIMARY KEY);"
..Execute sql
sql = _
"INSERT INTO Sequence (seq) VALUES" & _
" (1);"
..Execute sql
sql = _
"INSERT INTO Sequence (seq)" & _
" SELECT Units.nbr + Tens.nbr FROM" & _
" (SELECT nbr FROM (SELECT 0 AS" & _
" nbr FROM Sequence UNION ALL SELECT" & _
" 1 FROM Sequence UNION ALL SELECT" & _
" 2 FROM Sequence UNION ALL SELECT" & _
" 3 FROM Sequence UNION ALL SELECT" & _
" 4 FROM Sequence UNION ALL SELECT" & _
" 5 FROM Sequence UNION ALL SELECT" & _
" 6 FROM Sequence UNION ALL SELECT" & _
" 7 FROM Sequence UNION ALL SELECT" & _
" 8 FROM Sequence UNION ALL SELECT" & _
" 9 FROM Sequence) AS Digits) AS" & _
" Units, (SELECT nbr * 10 AS nbr" & _
" FROM (SELECT 0 AS nbr FROM Sequence" & _
" UNION ALL SELECT 1 FROM Sequence" & _
" UNION ALL SELECT 2 FROM Sequence" & _
" UNION ALL SELECT 3 FROM Sequence" & _
" UNION ALL SELECT 4 FROM Sequence" & _
" UNION ALL SELECT 5 FROM Sequence" & _
" UNION ALL SELECT 6 FROM Sequence"
sql = sql & _
" UNION ALL SELECT 7 FROM Sequence" & _
" UNION ALL SELECT 8 FROM Sequence" & _
" UNION ALL SELECT 9 FROM Sequence)" & _
" AS Digits) AS Tens WHERE Units.nbr" & _
" + Tens.nbr <> 1;"
..Execute sql
sql = _
"CREATE TABLE Customers (CustomerID" & _
" NCHAR(5) PRIMARY KEY, CompanyName" & _
" NVARCHAR(40) NOT NULL, ContactName" & _
" NVARCHAR(30));"
..Execute sql
sql = _
"INSERT INTO Customers (CustomerID," & _
" CompanyName, ContactName) SELECT" & _
" DT1.CustomerID, DT1.CompanyName," & _
" DT1.ContactName FROM ( SELECT" & _
" DISTINCT 'ALFKI' AS CustomerID," & _
" 'Alfreds Futterkiste' AS CompanyName," & _
" 'Maria Anders' AS ContactName" & _
" FROM Sequence UNION ALL SELECT" & _
" DISTINCT 'ANATR', 'Ana Trujillo" & _
" Emparedados y helados', 'Ana" & _
" Trujillo' FROM Sequence UNION" & _
" ALL SELECT DISTINCT 'ANTON'," & _
" 'Antonio Moreno Taquería', 'Antonio" & _
" Moreno' FROM Sequence UNION ALL" & _
" SELECT DISTINCT 'AROUT', 'Around" & _
" the Horn', 'Thomas Hardy' FROM" & _
" Sequence UNION ALL SELECT DISTINCT" & _
" 'BERGS', 'Berglunds snabbköp'," & _
" 'Christina Berglund' FROM Sequence" & _
" UNION ALL SELECT DISTINCT 'BLAUS',"
sql = sql & _
" 'Blauer See Delikatessen', 'Hanna" & _
" Moos' FROM Sequence UNION ALL" & _
" SELECT DISTINCT 'BLONP', 'Blondel" & _
" père et fils', 'Frédérique Citeaux'" & _
" FROM Sequence UNION ALL SELECT" & _
" DISTINCT 'BOLID', 'Bólido Comidas" & _
" preparadas', 'Martín Sommer'" & _
" FROM Sequence UNION ALL SELECT" & _
" DISTINCT 'BONAP', 'Bon app'''," & _
" 'Laurence Lebihan' FROM Sequence)" & _
" AS DT1;"
..Execute sql
sql = _
"CREATE PROCEDURE GetCustomersFromList" & _
" ( delimted_text MEMO, delimiter" & _
" VARCHAR(4) = ',' ) AS SELECT" & _
" C1.CustomerID, C1.CompanyName," & _
" C1.ContactName FROM Customers" & _
" AS C1 INNER JOIN ( SELECT MID(I1.input_string," & _
" S1.seq, MIN(S2.seq) - S1.seq" & _
" - LEN(delimiter)) AS param FROM" & _
" ( SELECT DISTINCT delimted_text" & _
" AS input_string FROM SEQUENCE" & _
" AS S3 ) AS I1, SEQUENCE AS S1," & _
" SEQUENCE AS S2 WHERE MID(delimiter" & _
" & I1.input_string & delimiter," & _
" S1.seq, LEN(delimiter)) = delimiter" & _
" AND MID(delimiter & I1.input_string" & _
" & delimiter, S2.seq, LEN(delimiter))" & _
" = delimiter AND S1.seq < S2.seq" & _
" AND S1.seq BETWEEN 1 AND LEN(delimiter)" & _
" + LEN(delimted_text) + LEN(delimiter)" & _
" AND S2.seq BETWEEN 1 AND LEN(delimiter)"
sql = sql & _
" + LEN(delimted_text) + LEN(delimiter)" & _
" GROUP BY I1.input_string, S1.seq" & _
" HAVING LEN(MID(I1.input_string," & _
" S1.seq, MAX(S2.seq) - S1.seq" & _
" - LEN(delimiter))) > 0 ) AS LoadTable" & _
" ON C1.CustomerID = LoadTable.param;"
..Execute sql
sql = _
"EXECUTE GetCustomersFromList" & _
"'ANTON,BLAUS,BOLID';"
Dim rs
Set rs = .Execute(sql)
MsgBox rs.GetString
End With
Set .ActiveConnection = Nothing
End With
End Sub
Jamie.
--