I'm trying to write a function that I can use across multiple forms (which are the same format) to analyze some data. I have successfully built the recordset but now I'm not sure if I can use it without providing specific field names in the recordset. Here's the part of the function I am concerned about:
Now if I want to use the values of the fields in the recordset, is there a way to do something like this (I know the following does not work)?
Code:
Private Function ThicknessCalculations(txtThickValue1 As TextBox, _
txtThickValue2 As TextBox, txtThickValue3 As TextBox, _
txtThickValue4 As TextBox, txtThickValue5 As TextBox, _
txtThickAve As TextBox, txtThickRange As TextBox, _
txtThickMR As TextBox, ParameterDescription As String, _
txtDateTime As TextBox, cboTargetThickness As ComboBox, _
txtThickTolerance As TextBox)
'Calculate Moving Range
'Save current record
DoCmd.RunCommand acCmdSaveRecord
'Establish Recordset
Dim strSQL As String
strSQL = "select [" & txtDateTime.ControlSource & "]," & _
"[" & cboTargetThickness.ControlSource & "]," & _
"[" & txtThickAve.ControlSource & "]" & _
" from [" & Form.Name & " Production Log]" & _
" where [" & txtThickAve.ControlSource & "] is not null" & _
" and [" & cboTargetThickness.ControlSource & "]= " & _
cboTargetThickness.Value & _
" order by [" & txtDateTime.ControlSource & "]"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
End Function
Now if I want to use the values of the fields in the recordset, is there a way to do something like this (I know the following does not work)?
Code:
varSPCField = rs! & "[" & txtThickAve.ControlSource & "]"