G
Guest
Hi!
I'm still fooling around with queries, just for the fun of it! Now I noticed
a problem and I don't know what causes it. I have a table named Table1 with
fields Firstname (text) and Money (double). I have the following two subs:
Sub QryTable1()
Dim f As String
f = "Money"
Dim db As Database
Dim qryDef As QueryDef
Dim strSQL As String
strSQL = "SELECT Firstname, SUM(' " & f & " ') AS TotalSum FROM Table1 GROUP
BY Firstname;"
Set db = CurrentDb
Set qryDef = db.CreateQueryDef("MyQuery1", strSQL)
End Sub
Sub QryTable2()
Dim db As Database
Dim qryDef As QueryDef
Dim strSQL As String
strSQL = "SELECT Firstname, SUM(Money) AS TotalSum FROM Table1 GROUP BY
Firstname;"
Set db = CurrentDb
Set qryDef = db.CreateQueryDef("MyQuery2", strSQL)
End Sub
Both of the subs should do the same thing, the upper just has a variable in
the strSQL. When I run the subs they both run normally, I don't get any error
messages. But when I try to open the queries only the second one opens and
shows me the datasheet view. The first one gives me an error message: "Data
type mismatch in criteria expression." I click help and get the following
explanation: "The criteria expression in a Find method is attempting to
compare a field with a value whose data type does not match the field’s data
type."
If I open the queries in design view, there is a difference. In the first
query the second field says: TotalSum: Sum('Money'), and in the second query
it is: TotalSum: Money.
Does anyone know why this happens?
-Beginner-
I'm still fooling around with queries, just for the fun of it! Now I noticed
a problem and I don't know what causes it. I have a table named Table1 with
fields Firstname (text) and Money (double). I have the following two subs:
Sub QryTable1()
Dim f As String
f = "Money"
Dim db As Database
Dim qryDef As QueryDef
Dim strSQL As String
strSQL = "SELECT Firstname, SUM(' " & f & " ') AS TotalSum FROM Table1 GROUP
BY Firstname;"
Set db = CurrentDb
Set qryDef = db.CreateQueryDef("MyQuery1", strSQL)
End Sub
Sub QryTable2()
Dim db As Database
Dim qryDef As QueryDef
Dim strSQL As String
strSQL = "SELECT Firstname, SUM(Money) AS TotalSum FROM Table1 GROUP BY
Firstname;"
Set db = CurrentDb
Set qryDef = db.CreateQueryDef("MyQuery2", strSQL)
End Sub
Both of the subs should do the same thing, the upper just has a variable in
the strSQL. When I run the subs they both run normally, I don't get any error
messages. But when I try to open the queries only the second one opens and
shows me the datasheet view. The first one gives me an error message: "Data
type mismatch in criteria expression." I click help and get the following
explanation: "The criteria expression in a Find method is attempting to
compare a field with a value whose data type does not match the field’s data
type."
If I open the queries in design view, there is a difference. In the first
query the second field says: TotalSum: Sum('Money'), and in the second query
it is: TotalSum: Money.
Does anyone know why this happens?
-Beginner-