Hi All,
I'm trying to assign a value returned by a custom vba function to a textbox on a report. The function uses two parameters that are passes from the call in the textbox. I tried setting the textbox value to:
=Bedrag(0, "Deelgebied_1")
or something similar. I have around forty different combinations for these parameters (different integers, n.g. 1,"Deelgebied_2"; 1,"Deelgebied_3"; 10, "Deelgebied_1"; etc.).
This is the code in the function:
The fieldnames are in Dutch, so they probably won't mean a lot to you.
The problem is, I don't get any values returned, but an #error value in the textbox. I think something goes wrong with opening the recordset, because if I put a msgbox before the line:
the messagebox pops up. But if I put the msgbox line after the codeline mentioned above, I get no msgbox.
What is wrong with my sql/openrecordset statement?
Thanks in advance for any help! Please tell me if I need to further clarify what I'm trying to do.
Best regards,
Martijn Senden.
I love deadlines. I like the whooshing sound they make as they fly by.
- Douglas Adams -
I'm trying to assign a value returned by a custom vba function to a textbox on a report. The function uses two parameters that are passes from the call in the textbox. I tried setting the textbox value to:
=Bedrag(0, "Deelgebied_1")
or something similar. I have around forty different combinations for these parameters (different integers, n.g. 1,"Deelgebied_2"; 1,"Deelgebied_3"; 10, "Deelgebied_1"; etc.).
This is the code in the function:
Code:
Public Function Bedrag(i As Integer, strDeelgebied As String)
Dim strSQL As String, intJaar As Integer, rstResult As Recordset
intJaar = Year(Date)
'Create a recordset of the costs for the current year
strSQL = "SELECT tblVerkeersborden.Deelgebied, Sum(tblVerkeersborden.Vervangingsprijs) AS KostenJaar" & Chr(10) & _
"FROM tblVerkeersborden" & Chr(10) & _
"WHERE tblVerkeersborden.Vervangingsdatum>#12/31/" & intJaar + (i - 1) & "# And tblVerkeersborden.Vervangingsdatum<#1/1/" & intJaar + (i + 1) & "#" & Chr(10) & _
"GROUP BY tblVerkeersborden.Deelgebied" & Chr(10) & _
"HAVING tblVerkeersborden.Deelgebied = " & strDeelgebied & ";"
Set rstResult = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
'Return the results from the Recordset to the textfield in the report
With rstResult
If .BOF Then 'No records were found for this year
Bedrag = 0
Else 'Records were found for this year
Bedrag = .Fields("KostenJaar").value
End If
End With
End Function
The fieldnames are in Dutch, so they probably won't mean a lot to you.
The problem is, I don't get any values returned, but an #error value in the textbox. I think something goes wrong with opening the recordset, because if I put a msgbox before the line:
Code:
Set rstResult = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
What is wrong with my sql/openrecordset statement?
Thanks in advance for any help! Please tell me if I need to further clarify what I'm trying to do.
Best regards,
Martijn Senden.
I love deadlines. I like the whooshing sound they make as they fly by.
- Douglas Adams -