Passing field name as a parameter

G

Guest

I am creating a new function and need to pass the name of a field as a
parameter. I am passing a query name and it works fine. But then I need to
use the field, also a parameter but can't figure out how to convert the name
so it can be used and not look like a string. Below is my before creating
the new function code (that works) and then my attempt and creating a
function out of it.

Thanks for the help,
Dave

RS defined as a global variable / Dim db As Database, RS As Recordset

Original code
Set RS = db.OpenRecordset("TreeLevel1", dbOpenDynaset, dbReadOnly)
Do Until RS.EOF
strNode1Text = StrConv("Level1" & RS![ProcessID], vbLowerCase)
strVisibleText = RS![PID]
Set nodCurrent = objTree.Nodes.Add("Level0CV", tvwChild)
nodCurrent.Text = strVisibleText ' Text.
nodCurrent.Key = strNode1Text ' Unique ID."
nodCurrent.Image = PBitmap
nodCurrent.Tag = RS![ProcessID]
RS.MoveNext
Loop
RS.Close

New function (needs help)
Private Function AdddbNode(QryName As String, LevelText As String,
UniqueIDText As String, VisibleText As String, NodeName As String, NBitmap As
Integer, NodeTag As String) As Boolean

Set RS = db.OpenRecordset(QryName, dbOpenDynaset, dbReadOnly)
Do Until RS.EOF
strNode1Text = StrConv(LevelText & RS!UniqueIDText, vbLowerCase)
strVisibleText = RS!VisibleText
Set nodCurrent = objTree.Nodes.Add(NodeName, tvwChild)
nodCurrent.Text = strVisibleText ' Text.
nodCurrent.Key = strNode1Text ' Unique ID."
nodCurrent.Image = NBitmap
nodCurrent.Tag = RS!NodeTag
RS.MoveNext
Loop
RS.Close
AdddbNode = True
End Function
 
T

Tim Ferguson

I am creating a new function and need to pass the name of a field as a
parameter. I am passing a query name and it works fine. But then I
need to use the field, also a parameter but can't figure out how to
convert the name so it can be used and not look like a string.

Sorry, I didn't understand any of the code you posted, but the answer to
this question is the .Fields property:-

varMyValue = rs.Fields(paramFieldNameAsString).Value


Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top