Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to generalize recordset variables? 1

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
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:

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 & "]"
 
Something like...

Rs.fields(1).Value


Is that what you are after?

Or perhaps...

Rs.Fields(txtThickAve.ControlSource).value


Note Fields is the default collection of a recordset and value is the default property of a field.
 
that is what i was looking for. thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top