Well, this is sort of complicated.
The third argument of the DCount is an SQL Where clause without the
"WHERE" keyword. In a Where clause, string or text values must have
string delimiters: either quote marks (") or apostrophe ('). But the
entire argument must also be encased in string delimiters and to throw yet
another thing to gum the works, you've got a variable rather than a
literal string value.
So what you want to be evaluated (after the variable value insertion) is:
[Crate] = "7"
So if I put quotes around the whole thing, I get
"[Crate] = "7""
This will error because of the way the interpreter reads the quotes. In
order to put a quote within a quoted string, you have to double the
quotes:
"[Crate] = ""7"""
But now I need to replace the explicit 7 with the variable:
"[Crate] = "" & CrateNum & """
But this will error because now we have two different strings that have to
be concatenated and the interpreter isn't reading the quotes right again.
to fix it, you have to douple the inner quotes again:
"[Crate] = """ & CrateNum & """"
Now, I said you can also do this with apostophes. So let me repeat the
process:
[Crate] = '7'
can be surrounded with quotes this way and it will not error.
"[Crate] = '7'"
But adding the variable again:
"[Crate] = ' & CrateNum & '"
gives us two incomplete strings. We need to add a quote to each:
"[Crate] = '" & CrateNum & "'"
So either:
"[Crate] = '" & CrateNum & "'"
or
"[Crate] = """ & CrateNum & """"
will work. If it's possible for your data to have an apostrophe in it,
you have to use the second.
You can also use the Chr$(34) character (which the code for a quote) like
this:
"[Crate] = " & Chr$(34) & CrateNum & Chr$(34)
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
DawnP277 said:
Thak you Roger that worked.
So for future reference, a value that is a string needs to have an & in
the
front and bak enclosed in quotes?
Roger Carlson said:
Since CrateNum is a string, the DCount should be:
IntCount = DCount("[ID]", "FinisherTable", _
"[Crate] = '" & CrateNum & "'")
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
I have a Dcount in VB that is getting a syntax error getting a runtime
error
3075.
Here is my code.
If someone could tell me what I have wrong that would be appreciated.
Private Sub SerialNum_AfterUpdate()
Dim Serial As Variant
Dim fcrate As String
Dim IntCount As Variant
Dim CrateNum As String
Serial = DLookup("[TestParm]", "Tabledata", "[Serial Number] =
Form![SerialNum]")
Select Case Serial
Case "LOW"
fcrate = Forms![CratesUsed]![Text0]
Case "MED"
fcrate = Forms![CratesUsed]![Text2]
Case "HIGH"
fcrate = Forms![CratesUsed]![Text4]
End Select
CrateNum = CStr(fcrate)
IntCount = DCount("[ID]", "FinisherTable", _
"[Crate] = '" & CrateNum)
MsgBox (IntCount)
IntCount = IntCount + 1
End Sub
Thanks
Dawn