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 / January 2006

Tip: Looking for answers? Try searching our database.

Using a Variable Column Name in a recordSet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael - 19 Jan 2006 18:09 GMT
Hi guys.

I am trying to write a VB script that will go through several fields and
columns and update the appropriate information. I have columns like building
name, dollar amount, beginning year, end year, and also columns for years
1960-2005. Essentially, I am tracking the value of an object throughout its
life time.

I am having difficulty trying to use a variable as the column name... Here
is what I have so far..

Dim currConnection As New ADODB.Connection
Dim recordSet As New ADODB.recordSet
Dim currDB As Database

Set currDB = CurrentDb
Set currConnection = CurrentProject.Connection
Set recordSet = New ADODB.recordSet

recordSet.Open "SELECT * FROM test_OUR_UNIVERSE", currConnection,
adOpenDynamic, adLockOptimistic

For i = 1960 To 2005

   Do While Not recordSet.EOF
   recordSet![" & i & "] = i     <--- Here is what I am having difficulty
with
   recordSet.MoveNext
   Loop
   recordSet.MoveFirst
   
Next
recordSet.Close

-------

I want to use:
    recordSet![" & i & "]
so that it will update the appriopriate column when the loop is there...

How do I use a variable in this fashion?

I really appreciate any assistance you could provide.

Thanks.

-Michael
JohnV - 19 Jan 2006 19:29 GMT
Hello Michael,

Try using:

recordset(i) -- this will reference the field specified.

JohnV

> Hi guys.
>
[quoted text clipped - 43 lines]
>
> -Michael
Michael - 24 Jan 2006 15:10 GMT
Great! Thanks!

> Hello Michael,
>
[quoted text clipped - 51 lines]
> >
> > -Michael
 
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.