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 May 30th, 2006, 02:13 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a var into the name of another var or field.

Ok, here is what I am trying to do:

Dim i As Byte
For i = 1 To 7
    Set Rst = CurrentDb.OpenRecordset("SELECT * from tbl_Divisao WHERE CodigoDivisao =" & i & "and Pago = 0")
    While Not Rst.EOF
      sum&i = sum&i + Rst!Valor
      Rst.MoveNext
    Wend
Me.total&i = sum&i
Next

These &i are just for the example, they dont work. I want to know how to make them work =) I mean, I want in each FOR to create sum1 to sum7 and use them in Me.Total1 to Me.Total7

hope I made myself clear....

 
Old May 30th, 2006, 02:20 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

A good way to do this would be to use an array

Dim sum(7) as double
for i = 1 to 7
  ...
  sum(i) = sum(i) + Rst!Valor
  ...
Me.Form.Controls("total" & i) = sum(i)
Next


Mike
EchoVue.com
 
Old May 30th, 2006, 02:31 PM
Registered User
 
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much.. it worked =)

 
Old May 30th, 2006, 03:47 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Good to hear! It's always a relief when it actually works.

Welcome to the forum - I haven't found a better resource for VBA yet!

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
var,text ,..... angelboy SQL Language 2 May 29th, 2007 11:37 AM
"Out of scope" var??? yankleber XSLT 2 March 31st, 2007 03:53 AM
var as variable incredi-man Javascript 2 September 16th, 2006 11:46 AM
Dissapearing VAR topshed Classic ASP Databases 5 June 3rd, 2005 01:34 PM
Temp Var in For Each pbernardo XSLT 5 November 14th, 2003 06:45 PM





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