Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 6th, 2005, 02:46 PM
gharshfield gharshfield is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 gharshfield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Help with inclusion of variable into a field name in code

This is example code that I can not get to work that I have in a Access Form. There are several
text boxes on the form that that are named sequentially that I would like to have evaluated. (ie txtN1, txtN2 ...ect)
Any suggestions would be greatly appreciated
Greg


Private Sub buttCode_Click()
Dim varCount
Select Case cbTest
Case True
varCount = 1
While varCount < 6
[txtN & varCount &].Value = varCount ' can not get this to work correctly
varCount = varCount + 1
Wend
Case False
varCount = 1
While varCount < 6
[txtN & varCount &].Value = varCount * 2 ' can not get this to work correctly
varCount = varCount + 1
Wend
End Select
End Sub

Reply With Quote
  #2  
Old January 6th, 2005, 02:59 PM
Mythomep Mythomep is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Zaandam, The Netherlands
Posts: 70 Mythomep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 37 sec
Reputation Power: 5
Send a message via MSN to Mythomep
Cool

Hi,

Breakdown of your code:

  • Form with at most 5 textboxes (base 0)
  • Check for some test and put number in textbox.
Try to use this:

Code:
 Private Sub buttCode_Click()
   Dim lCounter As Long
   
   Select Case cbTest
   Case True
 	For lCounter = txtValue.LBound To txtValue.UBound
 	  txtValue(lCounter).Text = lCounter
 	Next
   Case False
 	For lCounter = txtValue.LBound To txtValue.UBound
 	  txtValue(lCounter).Text = lCounter
 	Next
   End Select
 End Sub
 


To make this work, all you need to do is name all your textboxes the same (txtValue in this code) and make it a control array (should be automatic when you name two controls the same). Then use this code and it should work.

Grtz.©

M.

Reply With Quote
  #3  
Old January 6th, 2005, 04:14 PM
gharshfield gharshfield is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 gharshfield User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Access Form will not all text boxes with the same name

I tried to set up you code within my form and rename the all the text boxes to the same name but Access will not allow multiple textboxes with the same name. Any other thoughts?

Thanks for your comments.
Greg

Reply With Quote
  #4  
Old January 13th, 2005, 10:55 AM
Mythomep Mythomep is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Zaandam, The Netherlands
Posts: 70 Mythomep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 37 sec
Reputation Power: 5
Send a message via MSN to Mythomep
Cool This might be an option for you...

Hi,

I am not very familiar with programming in MS-Access. In fact, I try to avoid it at almost any cost. However, you might be able to use a for each control loop and check the type of the control. Basically this works just like the control array solution I presented in an earlier post. Please consult the MS-Access help on the correct syntax for looping through all the controls, basic idea is this:

Code:
  Dim ctlCurrentControl as Control
 
  For Each ctlCurrentControl in Me.Controls
	If (Typename(ctlCurrentControl) = "Textbox") Then
	  ' Input relevant value in the .Text property of the textbox.
	  ctlCurrentControl.Text = "Value x"
	End if
  Next


Note however that I am not sure about the correct syntax when it comes to MS-Access forms and I did not include code to recognize what the current control number is. You can access the name property of the current control. That name you can use to see what control you are currently looking at. The Name property returns a string, thus you can inspect it against a "normal" string that you can construct.

Grtz.©

M.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Help with inclusion of variable into a field name in code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway