+ Reply to Thread
Results 1 to 7 of 7

Still stuck on this code clleanup

  1. #1
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Still stuck on this code clleanup

    I have multiple userforms that have textboxes with the same name e.g.txtSalary. I have duplicated code in each userform and want to place code in a standard module. Example below. When I run the code I get a runtime error "Object Required". I guess that I have to point the code to the specific object somehow?

    Cheers

    Peter

    In userform code

    Private Sub txtSalary_Change()
    RemDec
    End Sub

    In standard module code

    Public Sub RemDec()
    If txtSalary.Text = "." Then
    txtSalary.Text = ""
    End If
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,624
    Try:
    If FormName.txtSalary.Text =...
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Thanks Proton

    Yes that works but it doesn't cut down on the code required - I have 20 userforms that have common textboxes and would have to make 20 entries. How can one point code in a standard module to the active userform, without specifically naming the userform?

    Cheers

    Peter

  4. #4
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    To the best of my knowledge, you need an event code for that but I don't think the Userform collection property supports a class event to link all the userforms.
    HTH
    Myles

    ...constantly looking for the smoother pebble while the whole ocean of truth lies before me.

  5. #5
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Thanks Myles

    I guess that it can't be done!

    Cheers

    Peter

  6. #6
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    Pass the form calling the routine as a parameter:

    Please Login or Register  to view this content.

    HTH
    Col
    Last edited by colofnature; 09-24-2006 at 08:10 PM.
    If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.

  7. #7
    Forum Contributor
    Join Date
    12-16-2005
    Posts
    161

    Thanks Col

    It works - have saved me many lines of code!

    Cheers

    Peter (now happy)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1