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 February 24th, 2008, 02:05 PM
Registered User
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Variable used in recordset field name

I have a output table in Access that contains 30 fields named Field1 thru Field30. The program loops through an input table that have values that need to be placed in the appropriate fields in the output table. Each input record contains a value, and the field number that it is to be placed in the output table.

To accomplish this the code uses a variable in the output recordset field name. When the code is run, the error "Item not found in this collection" is returned. It appears that the field name is not being interpreted as intended. Any ideas on how the syntax below should be adjusted??

THANKS

rsOut.AddNew
Do while not rsIn.Eof
   MVar = "Field" & rsIn!FieldNum
   rsOut![ & MVar & ] = rsIn!InputData
   rsIn.MoveNext
Loop
rsOut.Update


 
Old February 24th, 2008, 04:18 PM
Registered User
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Solved:

MVar = "Field" & rsIn!FieldNum
rsOut(MVar) = rsIn!InputData







Similar Threads
Thread Thread Starter Forum Replies Last Post
Changeing a Recordset Name With a Variable? Winners Access VBA 2 August 22nd, 2007 02:10 PM
Variable Recordset Field Name Codesucks VB Databases Basics 6 June 1st, 2004 07:15 AM
Create a dynamic variable from a recordset tdaustin Classic ASP Basics 3 May 13th, 2004 11:04 PM
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.