Results 1 to 11 of 11

Thread: More code... [resolved]

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Resolved 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:
    1. Private Sub Command1_Click()
    2. Dim ctrl As Control
    3. For Each ctrl In Form1
    4. If ctrl = TextBox Then
    5. ctrl.BackColor = Text1.Text
    6. End If
    7. DoEvents
    8. Next
    9. End Sub
    Last edited by thegreatone; Mar 31st, 2005 at 12:15 PM.
    Zeegnahtuer?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: More code... that i think should work, but doesn't :(

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim ctrl As Control
    5. For Each ctrl In Form1
    6.   If typeof ctrl is TextBox Then
    7.     ctrl.BackColor = Text1.Text
    8.   End If
    9.   DoEvents
    10. Next
    11. End Sub
    Last edited by dglienna; Mar 31st, 2005 at 12:12 PM.

  3. #3

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    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.
    Zeegnahtuer?

  4. #4
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    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

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  6. #6

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: More code... that i think should work, but doesn't :(

    DGlienna, your code still failed to work.. sorry to say that.

    Other dude who posted routine (forgot your name already
    Thanks so much, that works well, and is modified to work now

    Pos Rep for both
    Zeegnahtuer?

  7. #7
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: More code... that i think should work, but doesn't :(

    No problem. Don't forget to mark your question as 'resolved'

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: More code... that i think should work, but doesn't :(

    Oops, again. Missed the l on Ctrl.

    Thanks.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Dim ctrl As Control
    2. For Each ctrl In Form1.Controls
    3.   If TypeOf ctrl Is TextBox Then
    4.     ctrl.BackColor = CLng(Text1.Text) 'Of course Text1.Text must contain a color value
    5.   End If
    6. Next

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: More code... [resolved]

    I've never needed that, as Ctrl was declared as a Control, so For Each Control in Forms works.

  11. #11

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: More code... [resolved]

    Thank you Joacim

    I've just noticed that myself
    Now i can save two ways of doing this Thanks
    Zeegnahtuer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width