spectrolab
05-10-2007, 05:53 PM
Hi all,
I have a report which has the following code in the On Open command:
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database, rst As Recordset
Dim TBLLoop As Integer, strColName As String
Dim intRecs As Integer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LU_ColumnHeadingsFull", dbOpenDynaset)
If rst.BOF Then GoTo rptexit 'no column headings!
rst.MoveLast
intRecs = rst.recordcount
rst.MoveFirst
strColName = rst![columnname]
Me("TXT1").ControlSource = strColName
Me("TXT1").Visible = True
Me("Lbl1").ControlSource = "=" & Chr(39) & strColName & Chr(39)
Me("Lbl1").Visible = True
If intRecs > 1 Then 'If more than one record, process more columns
For TBLLoop = 2 To intRecs
rst.MoveNext
strColName = rst![columnname]
Me("TXT" & TBLLoop).ControlSource = "= MakeResult([" & strColName & "])"
Me("TXT" & TBLLoop).Visible = True
Me("Lbl" & TBLLoop).ControlSource = "=" & Chr(39) & strColName & Chr(39)
Me("Lbl" & TBLLoop).Visible = True
Next TBLLoop
End If
rptexit:
rst.Close
Exit Sub
End Sub
Which uses the following public function
Public Function MakeResult(result As Variant, Accuracy As Single, AllowNegs As Boolean) As String
'Function used to display results
If IsNull(result) Then
MakeResult = "-"
Exit Function
End If
If result < Accuracy / 2 And AllowNegs = False Then
MakeResult = "X"
Else
Select Case Accuracy
Case 0.1
MakeResult = Format(result, "0.0")
Case 0.01
MakeResult = Format(result, "0.00")
Case 0.001
MakeResult = Format(result, "0.000")
Case 0.0001
MakeResult = Format(result, "0.0000")
Case 0.00001
MakeResult = Format(result, "0.00000")
End Select
End If
End Function
When I try to run the report, I get a Run Time error (2439)
The expression you entered has a function containing the wrong number of arguments.
On debug, the line
Me("TXT" & TBLLoop).ControlSource = "= MakeResult([" & strColName & "])"
is highlighted.
MakeResult works fine for other uses I have for it (creating a .SIF file), but in this instance it falls over.
Any ideas what might be wrong?
I have a report which has the following code in the On Open command:
Private Sub Report_Open(Cancel As Integer)
Dim dbs As Database, rst As Recordset
Dim TBLLoop As Integer, strColName As String
Dim intRecs As Integer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LU_ColumnHeadingsFull", dbOpenDynaset)
If rst.BOF Then GoTo rptexit 'no column headings!
rst.MoveLast
intRecs = rst.recordcount
rst.MoveFirst
strColName = rst![columnname]
Me("TXT1").ControlSource = strColName
Me("TXT1").Visible = True
Me("Lbl1").ControlSource = "=" & Chr(39) & strColName & Chr(39)
Me("Lbl1").Visible = True
If intRecs > 1 Then 'If more than one record, process more columns
For TBLLoop = 2 To intRecs
rst.MoveNext
strColName = rst![columnname]
Me("TXT" & TBLLoop).ControlSource = "= MakeResult([" & strColName & "])"
Me("TXT" & TBLLoop).Visible = True
Me("Lbl" & TBLLoop).ControlSource = "=" & Chr(39) & strColName & Chr(39)
Me("Lbl" & TBLLoop).Visible = True
Next TBLLoop
End If
rptexit:
rst.Close
Exit Sub
End Sub
Which uses the following public function
Public Function MakeResult(result As Variant, Accuracy As Single, AllowNegs As Boolean) As String
'Function used to display results
If IsNull(result) Then
MakeResult = "-"
Exit Function
End If
If result < Accuracy / 2 And AllowNegs = False Then
MakeResult = "X"
Else
Select Case Accuracy
Case 0.1
MakeResult = Format(result, "0.0")
Case 0.01
MakeResult = Format(result, "0.00")
Case 0.001
MakeResult = Format(result, "0.000")
Case 0.0001
MakeResult = Format(result, "0.0000")
Case 0.00001
MakeResult = Format(result, "0.00000")
End Select
End If
End Function
When I try to run the report, I get a Run Time error (2439)
The expression you entered has a function containing the wrong number of arguments.
On debug, the line
Me("TXT" & TBLLoop).ControlSource = "= MakeResult([" & strColName & "])"
is highlighted.
MakeResult works fine for other uses I have for it (creating a .SIF file), but in this instance it falls over.
Any ideas what might be wrong?