What's the context? Where are you trying to use this?
A Query will not have any reference to a "frm" object, even if it's been set
in code.
Just the NEED to do this suggests that your table design might not be properly
normalized: what are T6 and T7 and so on? Might you be "storing data in
fieldnames"?
--
John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see alsohttp://
www.utteraccess.com
Hi John,
I am using an unbound form "frmQAAdmin" which has 15 textboxes that
are visible only if available for a particular selection.
With in that selection there could be calculations that I need to
perform using the value in the textboxes
This is the function called on the enter Event of each textbox that is
called:
Public Function performCalculation() As Boolean
Dim strCtlname As String
Dim i As Integer
Dim sql As String
Dim vCalc
Dim sngCalc As Long
Dim rst As DAO.Recordset
Dim frm As Form
On Error GoTo Err_performCalculation
Set frm = forms!frmQAAdmin
'get control name and order
strCtlname = frm.ActiveControl.Name
i = Right(strCtlname, Len(strCtlname) - 1)
'check if control has a calculation
sql = "SELECT FIELD_CALCULATION FROM TMP_ADMIN WHERE
FORM_ADMIN_ITEM_ORDER_ID = " & i & ";"
Set rst = CurrentDb.OpenRecordset(sql)
With rst
if .recordcount>0 then
.MoveFirst
If Not IsNull(!FIELD_CALCULATION) Then
vCalc = Eval(!FIELD_CALCULATION)
frm.ActiveControl.value = vCalc
End If
End if
End With
performCalculation = True
Exit_performCalculation:
performCalculation = False
Exit Function
Err_performCalculation:
Select Case Err.Number
Case 11
MsgBox "Devision by zero is not allowed. Please Enter all
correct required amounts for calculation!"
strCtlname = "T" & i - 1
If frm.Controls(strCtlname).Visible = True Then
frm.Controls(strCtlname).SetFocus
Else
strCtlname = "C" & i - 1
frm.Controls(strCtlname).SetFocus
End If
Resume Exit_performCalculation
Case 13
MsgBox "Please Enter all Field required for calculation!"
strCtlname = "T" & i - 1
If frm.Controls(strCtlname).Visible = True Then
frm.Controls(strCtlname).SetFocus
Else
strCtlname = "C" & i - 1
frm.Controls(strCtlname).SetFocus
End If
Resume Exit_performCalculation
Case Else
DoCmd.Echo True
Call LogError(Err.Number, Err.Description,
"performCalculation of Module modQA")
Resume Exit_performCalculation
'MsgBox "Error " & Err.Number & " (" & Err.Description & ")
in procedure performCalculation of Module modQA"
End Select
End Function
Any way your suggestion of the Eval function saved me.
Thanks again,
Stefania