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!

comparing control name with string name

Status
Not open for further replies.

STPMB

Programmer
Sep 13, 2002
28
US
Is there some way to compare a control name with a string?.
Is it possible to build an control array without using the controls collection. I don't want to check every control on a form, only certain mandatory ones that need user input before exiting the form.
I tried defining a Control array and loading the array with the certain control names requiring user input. I then tried using the controls collection to compare each control name with the control names in my array to see if they needed validation but that didn't work. I don't know if it is even possible to do a comparison like acontrol.name = bcontrol.name.

Any suggestions would be helpful.

 
It is possible - I don't have my code in front of me but you can do things like frmFormName.Controls(i).Name and you can put this type of stuff into for next loops or whatever - I have a routine that compares textboxes on a form to a data dictonary so that it can check whether it's date number or text validation that's required.

Hope this helps...

I may not have the syntax completely correct as I say I don't have my code with me - sorry :(
 
You can always construct an array of controls, as opposed to a Control Array which is an object not an array.
Dim aryCtl() as textbox

Redim aryCtl(...) ' So we can Redim or Erase in Unload
Set aryCtl(0) = ....
Set aryCtl(1) = ....
For I = 0 to Ubound(aryCtl)
If aryCtl(I).Name = .........
Next

WARNING. Clear it in Unload event so Form will terminate.
Otherwise, there are circular references of form to control in array to form.
Erase aryCtl Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 

Here is an example for you...

[tt]Option Explicit

Private Sub Form_Load()

Dim C As Control

For Each C In Me.Controls

If TypeOf C Is TextBox Then
If InStr(1, C.Name, "What You have setup to match for") > 0 Then
'do your validation here
End If
End If
Next

End Sub
[/tt]

this will let you set up a pattern that you want to search for in textbox control names. Say you had the following in a form

Text1
Text2
txtValidate1
Text3
txtValidate2

And with the instr above you put in

[tt]If InStr(1, C.Name, "Valid") > 0 Then
[/tt]

You could test just for that.

I hope this helps, good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top