Wrox Programmer Forums
|
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 January 30th, 2007, 12:20 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default Variable field name

Hi,

I'm trying to find out if there is a way to use a variable for a field name such as:

Code:
sField = Me.txtLoc & 

    rsOver.AddNew
    rsOver![Overflow1] = rsReserve![sField]
    rsOver.Update


Thanks for any help,

Dave
 
Old January 31st, 2007, 10:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

sField = Me.txtLoc &

    rsOver.AddNew
    rsOver![Overflow1] = sField
    rsOver.Update

HTH

mmcdonal
 
Old January 31st, 2007, 10:47 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying! Thats not really what I was looking for though.
sField will hold the name of a field in rsReserve. I want to set Overflow1 equal to the value in the variable field. If I can do this then I'm going to loop through the recordset.

 
Old January 31st, 2007, 11:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Please write the pseudo code. Right now your code says:

The value of the sField variable equals the value in Me.txtLoc, and something else not specified.

Add a new record to the rsOver recordset,
rsOver recordset field Overflow1 is equal to some value in the rsReserve recordset called sField, but Not the variable sField.
Update the rsOver recordset.

You can use a variable to indicate some field name in a recordset. It appears you have TWO recordsets open at the same time, one called rsOver, and one called rsReserve. You want to pick a field from rsReserve, and add its value to rsOver. But you want that selection to be based on what is typed in the text box txtLoc. If that is the case, then you can do this:

sField = Me.txtLoc
'If there is a field name typed in txtLoc on the form, then it will be taken here.

Then:

   rsOver.AddNew
   rsOver("Overflow1") = rsReserve(sField)
   rsOver.Update

Did that work?


mmcdonal
 
Old January 31st, 2007, 12:24 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works perfectly.
Thanks once again, mmcdonal!






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
Select a field on a form, based on variable JAnthony Access VBA 2 April 17th, 2006 11:16 AM
Variable Recordset Field Name Codesucks VB Databases Basics 6 June 1st, 2004 07:15 AM
variable value field? crtltd HTML Code Clinic 1 October 19th, 2003 04:39 PM





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