+ Reply to Thread
Results 1 to 5 of 5

Compile error: Member already exists in an object module...Trying to create a form

Hybrid View

  1. #1
    Registered User
    Join Date
    03-11-2015
    Location
    Champaign, IL
    MS-Off Ver
    2010
    Posts
    2

    Compile error: Member already exists in an object module...Trying to create a form

    Hello all,

    I am trying to create a form to add new customers to a database for my homework assignment. I keep getting the compile error: member already exists in an object module from which this object module derives.

    My codes are as follows:
    Form:
    Private Sub cmdOK()
        'Copy input values to sheet.
        Dim lRow As Long
        Dim ws As Worksheet
        Set ws = Worksheets("Customer Database")
        lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        With ws
            .Cells(lRow, 1).Value = Me.Company_Name.Value
            .Cells(lRow, 2).Value = Me.Last_Name.Value
            .Cells(lRow, 3).Value = Me.First_Name.Value
            .Cells(lRow, 4).Value = Me.Address1.Value
            .Cells(lRow, 5).Value = Me.Address2.Value
            .Cells(lRow, 6).Value = Me.City.Value
            .Cells(lRow, 7).Value = Me.State.Value
            .Cells(lRow, 8).Value = Me.Zip_Code.Value
        End With
        
        'Clear input controls.
        Me.Company_Name.Value = ""
        Me.Last_Name.Value = ""
        Me.First_Name.Value = ""
        Me.Address1.Value = ""
        Me.Address2.Value = ""
        Me.City.Value = ""
        Me.State.Value = ""
        Me.Zip_Code.Value = ""
    End Sub
    
    Private Sub cmdCancel()
        'Close UserForm.
        Unload Me
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub
    And Module:
    Sub Customer_Database()
    '
    ' Customer_Database Macro
    ' Go to Customer Database Page
    '
    
    '
        Sheets("Customer Database").Select
        Range("Table1[Company Name]").Select
    End Sub
    Sub Vendor_Database()
    '
    ' Vendor_Database Macro
    ' Go to Vendor Database
    '
    
    '
        Sheets("Vendor Database").Select
        Range("B3").Select
    End Sub
    Sub Main_Menu()
    '
    ' Main_Menu Macro
    ' Return to Main Menu
    '
    
    '
        Sheets("Main Menu").Select
        Range("A1").Select
    End Sub
    Sub ShowCustomer()
        'Display Customer UserForm.
        ufrmCustomers.Show Modal
    End Sub

    What am I doing wrong?

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 03-11-2015 at 10:16 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Compile error: Member already exists in an object module...Trying to create a form

    Hello MonaP9,

    Welcome to the Forum!

    It would be easier to check your work for errors if you posted a copy of the workbook.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,982

    Re: Compile error: Member already exists in an object module...Trying to create a form

    When asking for help with a compile error always show the line of text that is highlighted when the error occurs.

    Change this line of code.

    Private Sub cmdCancel_Click()
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    03-11-2015
    Location
    Champaign, IL
    MS-Off Ver
    2010
    Posts
    2

    Re: Compile error: Member already exists in an object module...Trying to create a form

    Hi guys, so here is my workbook. I fixed that problem, but now when i put in data, it keeps reentering over the data.
    Attached Files Attached Files

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,982

    Re: Compile error: Member already exists in an object module...Trying to create a form

    This line of code is in your form (updated from what you posted initially):

        emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
    But you have not specified in the code which worksheet you want to look at. Therefore it defaults to the currently active worksheet, which is "Main Menu". You need to explicitly say which worksheet you want. (If the code were in a worksheet module, the reference would default to that worksheet instead of the active one.)

        emptyRow = WorksheetFunction.CountA(Worksheets("Customers").Range("A:A")) + 2
    I also think you want that to be +1, not 2, unless you want to leave a blank line after each new customer.

    I don't know what your assignment requires, but you may want to consider validation of the input data. For example, zip code should be 5 digits but I can enter FOOBAR without any problem.

    Note to other members who may wonder why I'm answering this: We have a rule against doing homework for people but in this case the OP has made a good effort to solve the overall problem and is asking specific, focused VBA questions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Member already exists in an object module form which this object module derives error
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-01-2014, 03:14 AM
  2. [SOLVED] Compile Error in Hidden Module and Compile Error: Can't find project or library
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2013, 07:03 PM
  3. [SOLVED] Compile error: Method or data member not found.
    By ndtsteve in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-10-2012, 11:31 AM
  4. Compile Error: Method of data member not found (VBA)
    By vbatech in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 03-14-2012, 05:37 PM
  5. Replies: 3
    Last Post: 10-25-2011, 02:12 PM

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