
Problems with DCount function
Try concatenating the value of y onto the string instead of including it
in the string.
Since y is numeric, this will be:
x = DCount("[Projekt]", "Anteckningar Fr?ga", "[Projekt] = " & y)
Quote:
> I have a problem getting the right structure of a DCount expression.
> The background is this:
> I have a control on a form "Projekt" that is named "Index". "Index" is the
> keyfield of a table also named "Projekt". When I push a button in the form
> I call via a macro a Visual Basic Module.
> I want to count the number of posts of a table "Anteckningar" where the
> field "Projekt" in "Anteckningar" has the Value of "Index" (defined above).
> I use the DCount the following way.
> With CodeContextObject
> Dim x As Long
> Dim y As Long
> Dim strin As String
> Dim stri As String
> y = .Index
> x = DCount("[Projekt]", "Anteckningar Fr?ga", "[Projekt] = y")
> Beep
> stri = Str(x)
> strin = "Det finns " & stri
> strin = strin & " anteckningar till detta projekt"
> MsgBox strin, vbOKOnly, ""
> End With
> DCount("[Projekt]", "Anteckningar Fr?ga", "[Projekt] = y")
> ===============
> It seems to be the criteria that does not work.