469,643 Members | 1,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Function Error in Query Expression

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
1 3155
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.

Similar topics

7 posts views Thread by John Moore | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.