By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,829 Members | 1,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,829 IT Pros & Developers. It's quick & easy.

Function Error in Query Expression

P: n/a
I created a function module base on a query to provide a group record
total for a subform and which is posted to a field on the main form.
Everything seems to work fine except that I consistently receive an
error every time I attempt to create a new record on the main form.
However, there are no errors received when accessing existing records.
It is a Run-Time Error 3075 - Synax error (missing operator) in query
expression 'IDRef=' . And when opening the module, the following is
highlighted: Set rst = CurrentDb.OpenRecordset (strSQL). Here is the
code structure of the module:

Function GetTotalAdditional(IDRef) As Currency

Dim rst As Recordset, strSQL As String

strSQL = "Select TotalAdditional FROM qryAddCost WHERE IDRef = " &
IDRef

Set rst = CurrentDb.OpenRecordset(strSQL)

If rst.RecordCount = 0 Then
GetTotalAdditional = 0

Else
GetTotalAdditional = rst![TotalAdditional]

End If

rst.Close
Set rst = Nothing

Exit Function

End Function
The text box Control Source (AddCost) on the main form uses:
=[Forms]![frmMain]![sfrmAdditionalCosts]![TotalAdditionalCost]

On the subform (continuous forms) the field name is
(TotalAdditonalCost) and the Control Source is set to:
=GetTotalAdditional([IDRef])

The query (qryAddCosts) contains the IDRef as Group By and Total
Additional which is the sum of 3 groups of cost.

Based on the table (tblAdditionalCosts).

I have tried many different things, but to no avail. Any assistance
will be much appreciated. Thanks.
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ba***@safe-mail.net (Rolan) wrote in message news:<18*************************@posting.google.c om>...
I created a function module base on a query to provide a group record
total for a subform and which is posted to a field on the main form.
Everything seems to work fine except that I consistently receive an
error every time I attempt to create a new record on the main form.
However, there are no errors received when accessing existing records.
It is a Run-Time Error 3075 - Synax error (missing operator) in query
expression 'IDRef=' . And when opening the module, the following is
highlighted: Set rst = CurrentDb.OpenRecordset (strSQL). Here is the
code structure of the module:

Function GetTotalAdditional(IDRef) As Currency

Dim rst As Recordset, strSQL As String

strSQL = "Select TotalAdditional FROM qryAddCost WHERE IDRef = " &
IDRef

Set rst = CurrentDb.OpenRecordset(strSQL)

If rst.RecordCount = 0 Then
GetTotalAdditional = 0

Else
GetTotalAdditional = rst![TotalAdditional]

End If

rst.Close
Set rst = Nothing

Exit Function

End Function
The text box Control Source (AddCost) on the main form uses:
=[Forms]![frmMain]![sfrmAdditionalCosts]![TotalAdditionalCost]

On the subform (continuous forms) the field name is
(TotalAdditonalCost) and the Control Source is set to:
=GetTotalAdditional([IDRef])

The query (qryAddCosts) contains the IDRef as Group By and Total
Additional which is the sum of 3 groups of cost.

Based on the table (tblAdditionalCosts).

I have tried many different things, but to no avail. Any assistance
will be much appreciated. Thanks.


I suspect that IDRef is null when you begin creation of a new record,
thus your strSQL becomes invalid. Perhaps adding the block:

If IsNull(IdRef) Then
GetTotalAdditional = 0
Exit Function
End If

just below 'Dim rst as recordset... ' would patch it up.

Bruce
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.