Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining variables 1

Status
Not open for further replies.

Rubius

Programmer
May 12, 2000
57
CA
In access I have a form with a bunch of text boxes that I'm going to fill using code. they are named cost1, cost2, etc..<br><br>in vb code I want to be able to do this like this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If rst!cost &lt;&gt; &quot;Me!cost*i* Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!cost*i* = rst!cost<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i = i + 1<br>the stars around the i are there to show you the part thats incorrect.<br>something along those lines..anyway, all I need to know is how to combine the Me!cost and the i integer into something that increments. So I'll get Me!cost1 Me!cost2..etc every time the i variable is increased...thanks in advance!
 
You would check it like this:<br>dim check as string<br><br>check = &quot; me!cost' & i<br><br>if rst!cost &lt;&gt;&nbsp;&nbsp;check then <br><br>that should work <p>Walt III<br><a href=mailto:SAElukewl@netscape.net>SAElukewl@netscape.net</a><br><a href=
 
&nbsp;&nbsp;&nbsp;&nbsp;check = &quot;Me!cost' & i&quot;<br>here it auto puts the last quote on the end<br><br>&nbsp;&nbsp;&nbsp;&nbsp;If rst!cost &lt;&gt; check Then<br>this line probably works but I donno, doesn't matter because<br>&nbsp;&nbsp;&nbsp;&nbsp;&quot;Me!cost' & i&quot; = rst!cost<br>yells about this, expected blah blah<br>or<br>&nbsp;&nbsp;&nbsp;&nbsp;check = rst!cost<br>don't work because it's just setting check to rst!cost..<br><br>so no it didn't work.
 
Sorry I got this to work For a checkbox <br><br>&nbsp;&nbsp;&nbsp;&nbsp;i = 8<br>&nbsp;&nbsp;&nbsp;&nbsp;value = &quot;check&quot; & i<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;the value of the check box &quot; & Me(value)<br>try that it should work <p>Walt III<br><a href=mailto:SAElukewl@netscape.net>SAElukewl@netscape.net</a><br><a href=
 
when passing values I've had the best luck with<br><br>value = Me.Controls(&quot;text&quot; & x)
 
thanks peeps..both work and the knowledge of the one I didn't use will come in handy another day!
 
You might want to use a For ... Next instead of a Do ... Loop.<br>Then you don't have to use the i = i + 1 line, as it will loop as many time are in the for.<br><br>For Example, if you had six fields<br><br>For i = 1 to 6<br>&nbsp;&nbsp;&nbsp;If rst!cost &lt;&gt; Me(&quot;cost&quot; & i) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me(&quot;cost&quot; & i) = rst!cost<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.MoveNext<br>&nbsp;&nbsp;&nbsp;End if<br>Next i<br> <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top