P
pietlinden
I read this article... apparently I didn't understand it as well as I
thought I did...
http://www.mvps.org/access/queries/qry0013.htm
What I'm doing... (in case it helps).
I have a seriously denormalized table, that looks like this:
CREATE TABLE Induction(
RecordID Autonumber,
ANEMIA Number,
NEUTROPENIA Number,
.....
)
All the symptoms are in all caps (in case it matters). So I can
identify all those with a function.
because I have to normalize this mess, I'm inserting records into a
normalized table.
(PatientID, Symptom, Grade, CycleNumber, Phase)
so I created a single append query and then used Replace to modify the
SQL.
Here's the routine to do the replace...
Public Sub TestQuery(ByVal strFieldName As String)
Dim strSQL As String
Dim strNewSQL As String
Dim qdf As DAO.QueryDef
Dim qdfNew As DAO.QueryDef
Dim prm As DAO.Parameter
Set qdf = DBEngine(0)(0).QueryDefs("qapp Anemia")
strSQL = qdf.SQL
strNewSQL = Replace(qdf.SQL, "Anemia", strFieldName)
Debug.Print "Old SQL:"
Debug.Print qdf.SQL
Debug.Print
Debug.Print "New SQL"
Debug.Print strNewSQL
'CurrentDb.Execute strNewSQL, dbFailOnError
Set qdfNew = New QueryDef
qdfNew.SQL = strNewSQL
For Each prm In qdfNew.Parameters
prm.Value = Eval(prm.Name)
Next prm
qdf.Execute
Debug.Print qdf.RecordsAffected
End Sub
here's a sample output of the "TestQuery" function:
testquery "Allopecia"
Old SQL:
INSERT INTO HasToxicity ( [Record#], [Patient Initials], [Pt
Identifier], [Cycle#], Symptom, Grade )
SELECT [Toxicity Induction].[Record#], [Toxicity Induction].[Patient
Initials], [Toxicity Induction].[Pt Identifier], [Toxicity Induction].
[Cycle#], "Anemia" AS Symptom, [Toxicity Induction].ANEMIA
FROM [Toxicity Induction]
WHERE ((([Toxicity Induction].ANEMIA) Is Not Null));
'---routine returns this....
New SQL
INSERT INTO HasToxicity ( [Record#], [Patient Initials], [Pt
Identifier], [Cycle#], Symptom, Grade )
SELECT [Toxicity Induction].[Record#], [Toxicity Induction].[Patient
Initials], [Toxicity Induction].[Pt Identifier], [Toxicity Induction].
[Cycle#], "Allopecia" AS Symptom, [Toxicity Induction].Allopecia
FROM [Toxicity Induction]
WHERE ((([Toxicity Induction].Allopecia) Is Not Null));
when I try to run the query, I get "Too few parameters, expected
n" (see the article).
Even with the parameters supposedly getting evaluated, it still
returns the same error. What am I doing wrong?
It probably sounds like a lot of work to fix a few queries, but I have
lots of databases that are not normalized, so I'm trying to create a
routine that will automate most of the dirty work for me. so that's
why I'm doing all this in code...
Any ideas what I'm doing wrong? (Maybe I just need to take a walk or
something... )
Thanks for the help,
Pieter
thought I did...
http://www.mvps.org/access/queries/qry0013.htm
What I'm doing... (in case it helps).
I have a seriously denormalized table, that looks like this:
CREATE TABLE Induction(
RecordID Autonumber,
ANEMIA Number,
NEUTROPENIA Number,
.....
)
All the symptoms are in all caps (in case it matters). So I can
identify all those with a function.
because I have to normalize this mess, I'm inserting records into a
normalized table.
(PatientID, Symptom, Grade, CycleNumber, Phase)
so I created a single append query and then used Replace to modify the
SQL.
Here's the routine to do the replace...
Public Sub TestQuery(ByVal strFieldName As String)
Dim strSQL As String
Dim strNewSQL As String
Dim qdf As DAO.QueryDef
Dim qdfNew As DAO.QueryDef
Dim prm As DAO.Parameter
Set qdf = DBEngine(0)(0).QueryDefs("qapp Anemia")
strSQL = qdf.SQL
strNewSQL = Replace(qdf.SQL, "Anemia", strFieldName)
Debug.Print "Old SQL:"
Debug.Print qdf.SQL
Debug.Print
Debug.Print "New SQL"
Debug.Print strNewSQL
'CurrentDb.Execute strNewSQL, dbFailOnError
Set qdfNew = New QueryDef
qdfNew.SQL = strNewSQL
For Each prm In qdfNew.Parameters
prm.Value = Eval(prm.Name)
Next prm
qdf.Execute
Debug.Print qdf.RecordsAffected
End Sub
here's a sample output of the "TestQuery" function:
testquery "Allopecia"
Old SQL:
INSERT INTO HasToxicity ( [Record#], [Patient Initials], [Pt
Identifier], [Cycle#], Symptom, Grade )
SELECT [Toxicity Induction].[Record#], [Toxicity Induction].[Patient
Initials], [Toxicity Induction].[Pt Identifier], [Toxicity Induction].
[Cycle#], "Anemia" AS Symptom, [Toxicity Induction].ANEMIA
FROM [Toxicity Induction]
WHERE ((([Toxicity Induction].ANEMIA) Is Not Null));
'---routine returns this....
New SQL
INSERT INTO HasToxicity ( [Record#], [Patient Initials], [Pt
Identifier], [Cycle#], Symptom, Grade )
SELECT [Toxicity Induction].[Record#], [Toxicity Induction].[Patient
Initials], [Toxicity Induction].[Pt Identifier], [Toxicity Induction].
[Cycle#], "Allopecia" AS Symptom, [Toxicity Induction].Allopecia
FROM [Toxicity Induction]
WHERE ((([Toxicity Induction].Allopecia) Is Not Null));
when I try to run the query, I get "Too few parameters, expected
n" (see the article).
Even with the parameters supposedly getting evaluated, it still
returns the same error. What am I doing wrong?
It probably sounds like a lot of work to fix a few queries, but I have
lots of databases that are not normalized, so I'm trying to create a
routine that will automate most of the dirty work for me. so that's
why I'm doing all this in code...
Any ideas what I'm doing wrong? (Maybe I just need to take a walk or
something... )
Thanks for the help,
Pieter