Karen Schaefer
asked on
type Mismatch variable syntax
What is wrong with my syntax on
I doesn't seem to like the above statement - Note (i) is a varable
" WHERE (Quarter = '" & i & "') And [Year] = " & Year(Date) & "")
I doesn't seem to like the above statement - Note (i) is a varable
For i = 1 To 4
'rs1.MoveFirst
If rs.Fields("FreezeQ" & (i)) = -1 Then
If rs1.RecordCount = 0 Then
Dim strsql2 As String
strsql2 = "INSERT INTO tblSummaryQuartersFrozen" & _
" SELECT tblSummary.*" & _
" FROM tblSummary" & _
" WHERE (Quarter = '" & i & "') And [Year] = " & Year(Date) & ""
Debug.Print (strsql2)
curDB.Execute (strsql2)
ElseIf rs1.Fields("Quarter") = (i) Then
rs.MoveNext
ElseIf rs1.Fields("Quarter") <> i Then
curDB.Execute ("INSERT INTO tblSummaryQuartersFrozen" & _
" SELECT tblSummary.*" & _
" FROM tblSummary" & _
" WHERE (Quarter = '" & i & "') And [Year] = " & Year(Date) & "")
rs.MoveNext
End If
End If
Next i
ASKER
no that didn't work
What type of error did you get?
ASKER
Error 13 (Typemismatch)
Try:
" WHERE (Quarter = '" & i & "') And (Year = " & Year(Date) & ")"
/Tobias
try removing the & "" from the end of the string
Kelvin
Kelvin
ASKER
get the same error
that is what my original code was. see second version of the query statement
that is what my original code was. see second version of the query statement
Or:
" WHERE (Quarter = '" & CStr(i) & "') And (Year = " & Year(Date) & ")"
ASKER
try removing the & "" from the end of the string- no change
" WHERE (Quarter = '" & CStr(i) & "') And (Year = " & Year(Date) & ")"- no change
Still getting type mismatch.
Sounds like the types ain't the same. So "Quarter"-type in the database should be compared to the same type of variable. I assumed it was a string, but it might be some other type. And same for "Year". Type in DB should match Year(Date) output.
Here you have some type conversations you can try:
CBool Boolean Any valid string or numeric expression.
CByte Byte 0 to 255.
CCur Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
CDate Date Any valid date expression.
CDbl Double -1.79769313486231E308 to
-4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
CDec Decimal +/-79,228,162,514,264,337, 593,543,95 0,335 for zero-scaled numbers, that is, numbers with no decimal places. For numbers with 28 decimal places, the range is
+/-7.922816251426433759354 3950335. The smallest possible non-zero number is 0.000000000000000000000000 0001.
CInt Integer -32,768 to 32,767; fractions are rounded.
CLng Long -2,147,483,648 to 2,147,483,647; fractions are rounded.
CSng Single -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
CStr String Returns for CStr depend on the expression argument.
CVar Variant Same range as Double for numerics. Same range as String for non-numerics.
Here you have some type conversations you can try:
CBool Boolean Any valid string or numeric expression.
CByte Byte 0 to 255.
CCur Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
CDate Date Any valid date expression.
CDbl Double -1.79769313486231E308 to
-4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
CDec Decimal +/-79,228,162,514,264,337,
+/-7.922816251426433759354
CInt Integer -32,768 to 32,767; fractions are rounded.
CLng Long -2,147,483,648 to 2,147,483,647; fractions are rounded.
CSng Single -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
CStr String Returns for CStr depend on the expression argument.
CVar Variant Same range as Double for numerics. Same range as String for non-numerics.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tobais/Kelvin
That is exactly what I did and it turns out I was focusing on the wrong object (quarter) & not the Year - is where is syntax was wrong.
curDB.Execute ("INSERT INTO tblSummaryQuartersFrozen" & _
" SELECT tblSummary.*" & _
" FROM tblSummary" & _
" WHERE (Quarter = '" & i & "') And ((tblSummary.[Year])=Year( Date()))")
Thanks for the assist.
That is exactly what I did and it turns out I was focusing on the wrong object (quarter) & not the Year - is where is syntax was wrong.
curDB.Execute ("INSERT INTO tblSummaryQuartersFrozen" & _
" SELECT tblSummary.*" & _
" FROM tblSummary" & _
" WHERE (Quarter = '" & i & "') And ((tblSummary.[Year])=Year(
Thanks for the assist.
maybe
Open in new window
Regards