Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

Passing field name as a parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dave k - 05 Dec 2005 19:29 GMT
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
Tim Ferguson - 06 Dec 2005 18:28 GMT
=?Utf-8?B?ZGF2ZSBr?= <davek@discussions.microsoft.com> wrote in
news:52DB6B08-AE42-4CEC-914A-4F35EE34DC3A@microsoft.com:

> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.