Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2007, 12:46 PM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Changeing a Recordset Name With a Variable?

Hey i'm working on this form that fills a spreadsheet with info from a crosstab query, and i need a the recordset name to change as o loop though the table

   Do Until intCount = intColCount
   Set rstCheck = CurrentDb.OpenRecordset("Select * from qryJobOffersByYearCount where activeyear = " & intYearCount)
        If rstCheck.RecordCount > 0 Then
            Set rst = CurrentDb.OpenRecordset("Select * from qryJobOffersByYearCountCrosstab")
            If rst.RecordCount > 0 Then
            rst.MoveFirst
            introwcount = 2
             Do Until rst.EOF

                 objTimesheet.cells(introwcount, intCount) = rst![intYearCount]
                 introwcount = introwcount + 1
                 rst.MoveNext
             Loop
                 intCount = intCount + 1
             End If
        End If
        intYearCount = intYearCount + 1
   Loop

------
 objTimesheet.cells(introwcount, intCount) = rst![intYearCount]
i need this to change evey time its loops
for example i have these years
2003
2005
2006
2007
so as it gose though i need
objTimesheet.cells(introwcount, intCount) = rst![2003] and so on

i hope this makes sense

 
Old August 22nd, 2007, 01:32 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Winners,

Welcome to the forum!
You are unable to change the name of the Recordset, since the name is "hard coded".

I am unsure as to why you need to do this? Just populate the name based on the calculated values at run time...

Regards,

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old August 22nd, 2007, 02:10 PM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i got it working the way i need it 2
 Do Until rst.EOF
                 strSearch = CStr(intYearCount)
objTimesheet.cells(introwcount, intCount) = rst.Fields(strSearch).Value
                 introwcount = introwcount + 1
                 rst.MoveNext
             Loop






Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable used in recordset field name the4barkersab Access VBA 1 February 24th, 2008 04:18 PM
Passing recordset fields using a Variable johnslaughter Access 11 January 12th, 2007 12:45 PM
Variable Recordset Field Name Codesucks VB Databases Basics 6 June 1st, 2004 07:15 AM
assign a recordset to a variable biggen55 VB How-To 1 March 26th, 2004 02:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.