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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick line of VB6 Code

Status
Not open for further replies.

kermitforney

Technical User
Mar 15, 2005
374
US
Need help with a tiny lil line of VB code for an After_Update.

Once a txtbox has been updated I would like for other text boxes to be updated with the same value. Oh and they are all on the same form.

Thanks.
 
Text boxes don't have an After_Update event ... but they do have a Change Event.
Code:
Private Sub Text1_Change()
   Text2.Text = Text1.Text
End Sub
 
If you need to do ALL of the text boxes on the form, then
Code:
dim cCtl as Control
for each cCtl in me.Controls
   if typeof cctl is textbox then
        cctl.text = MyUpdateValue
   end if
next

If you need to do some textboxes and not others, then there are a couple of ways you can do it. One is to create a control array, using the same name for each textbox that you need to have updated. Another way is maybe a little easier: just use the Tag property. Put some value in the property for each text box you want to use in this way. So change the above code so:
Code:
dim cCtl as Control
for each cCtl in me.Controls
   if typeof cctl is textbox then
        if cctl.tag = "mymarkervalue" then
             cctl.text = MyUpdateValue
        end if
   end if
next

HTH

Bob
 
Hi!

Private Sub Text1_Validate(Index As Integer, Cancel As Boolean)
'First you may place some plausibity conditions, example only
Dim i As Integer
If IsNumeric(Text1(Index)) Then
For i = 0 To 7 'i have 8 Textboxes
Text1(i) = Text1(Index).Text
Next
Else
Cancel = True
End If
End Sub
 
A few comments:

Golom's code updates each text box with every keystroke, SmallTalkers does it as you leave the text box.

SmallTalker's contribution is an example of using a control array. However, the code only executes if the contents of the text box in question are able to be evaluated as numeric, and refuses attempts to leave the text box if they are not. This is not something the OP requested, so I'm pointing it out to avoid possible confusion.

Also, in order for a validate event to fire on a text box, its CausesValidation property has to be set to true (true is the default value).

If you don't need to check the value of the text box for validity prior to leaving it, consider using the LostFocus event instead.

HTH

Bob
 
Went with this one:

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

Not working though? Trying to have an AutoNumber textbox update 5 other textboxes after the Autonumber has filled in the number.
 
Um, are you talking about an Access form by any chance? In which case, put the same code in Text1_AfterUpdate.
 
Ok, yes, you're basically in the wrong forum. There's no such thing as an autonumber text box in VB6!

Bob
 
Yes it's in Access Joe and thanks for the reply (both Joe and Bob. I haven't been able to try your solution, I have been really sick for the past 3 days. Once I am better I will shoot you guys some stars based on my results. Thanks, again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top