|
-
Mar 31st, 2005, 11:39 AM
#1
Thread Starter
Frenzied Member
More code... [resolved]
I think from my code it is obvious what i am trying to do, but where did i go wrong ? And how can it be fixed ?
VB Code:
Private Sub Command1_Click()
Dim ctrl As Control
For Each ctrl In Form1
If ctrl = TextBox Then
ctrl.BackColor = Text1.Text
End If
DoEvents
Next
End Sub
Last edited by thegreatone; Mar 31st, 2005 at 12:15 PM.
Zeegnahtuer?
-
Mar 31st, 2005, 11:42 AM
#2
Re: More code... that i think should work, but doesn't :(
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim ctrl As Control
For Each ctrl In Form1
If typeof ctrl is TextBox Then
ctrl.BackColor = Text1.Text
End If
DoEvents
Next
End Sub
Last edited by dglienna; Mar 31st, 2005 at 12:12 PM.
-
Mar 31st, 2005, 11:45 AM
#3
Thread Starter
Frenzied Member
Re: More code... that i think should work, but doesn't :(
Thanks for the speedy reply, i get Syntax Error @
If typeof(ctr) is TextBox Then
and i don't know what to do... sorry.
-
Mar 31st, 2005, 11:48 AM
#4
PowerPoster
Re: More code... that i think should work, but doesn't :(
How about his routine that gets the form name passed. You can change the .text = "" to .backcolor = vbred,etc
/=============================================
Public Sub gClearForm(Fname As Form)
On Error GoTo errorhandler
'this routine will be called by each form
'it will clear the text boxes on the form
Dim MyControl As Control
For Each MyControl In Fname.Controls
If TypeOf MyControl Is TextBox Then MyControl.Text = ""
Next MyControl
Exit Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
errorhandler:
Screen.MousePointer = 0
MsgBox "An error occurred: [" & Err.Number & "] " & Err.Description & " - Source: " & Err.Source
End Sub
-
Mar 31st, 2005, 11:48 AM
#5
Re: More code... that i think should work, but doesn't :(
Sorry about that. Remove the ( ) and it should be fine.
My copy/paste skills aren't working right this morning.
Last edited by dglienna; Mar 31st, 2005 at 11:52 AM.
-
Mar 31st, 2005, 12:08 PM
#6
Thread Starter
Frenzied Member
-
Mar 31st, 2005, 12:13 PM
#7
PowerPoster
Re: More code... that i think should work, but doesn't :(
No problem. Don't forget to mark your question as 'resolved'
-
Mar 31st, 2005, 12:13 PM
#8
Re: More code... that i think should work, but doesn't :(
Oops, again. Missed the l on Ctrl.
Thanks.
-
Mar 31st, 2005, 12:14 PM
#9
Re: More code... that i think should work, but doesn't :(
The problem is the For Each statement. For Each ctrl In Form1? Form1 what? Form1.Controls!
VB Code:
Dim ctrl As Control
For Each ctrl In Form1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.BackColor = CLng(Text1.Text) 'Of course Text1.Text must contain a color value
End If
Next
-
Mar 31st, 2005, 12:16 PM
#10
Re: More code... [resolved]
I've never needed that, as Ctrl was declared as a Control, so For Each Control in Forms works.
-
Mar 31st, 2005, 12:18 PM
#11
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|