+ Reply to Thread
Results 1 to 12 of 12

SOLVED: Same code in two different sheets, yet 1004 error in one

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    SOLVED: Same code in two different sheets, yet 1004 error in one

    Hi everyone,

    I'm rather new to VBA, but I have managed to set up two userforms in two spreadsheets. The code for some of the functions is identical, for instance:

    -checking whether a branch name already exists in the spreadsheet (BNCheckButton_Click())
    -updating an existing record (UpdateExistingButton_Click())
    -saving a new record and exiting the form (OKCloseButton_Click())
    -saving a new record and starting a new record (OKNextButton_Click())
    -clearing the form (ClearForm())
    -saving the form (SaveForm())
    -filling the form (FillForm())

    The problem is, that the code works in one spreadsheet (FranchisingTest) but not the other (LeasingTest 2). I can't for the life of me work out what the difference is, and why it won't work in the second sheet.

    Essentially, when I open FranchisingTest, I can do all of the base things I need to do: search for an existing record, update it, create a new one, etc. But when I try to do the same thing in LeasingTest 2, I keep getting 'Run-time error: '1004': Application-defined or object-defined error', and it's generally pointing at one of these lines:

    Please Login or Register  to view this content.
    (in FillForm())
    or
    Please Login or Register  to view this content.
    (in SaveForm())

    I've attached both spreadsheets. Can anyone help me figure out what's going on? I'm tearing my hair out!!

    Thanks so much!
    FranchisingTest.xls
    LeasingTest 2.xls
    Last edited by caracolesa; 10-07-2012 at 08:58 AM. Reason: added code tags

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Hi caracolesa,

    Try the attached WorkBook now.

    Also see the "Please consider" note at the bottom of this post'
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor
    Join Date
    10-02-2012
    Location
    Bumi Nusantara
    MS-Off Ver
    Excel 2010; Excel 2016
    Posts
    136

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    please check the code in workbook LeasingTest 2.xls

    i found this code, perhaps it which caused error
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Hi Winon,

    Thanks so much for your help. Unfortunately, that doesn't seem to have worked. It's stopped throwing an error when BNCheckButton is clicked, but the code isn't doing what it should:

    -When BNCheckButton is clicked, it's not filling the form with pre-existing entries
    -When UpdateExistingButton is clicked, it's not overwriting the text in that row with what has been filled in on the userform
    -When OKNext is clicked, it saves the data to the spreadsheet, but still shows the 1004 error
    -When OKClose is clicked, it saves the data to the spreadsheet, but still shows the 1004 error.

    But thanks for getting rid of the error on BNCheckButton! What's the next step?

    Thanks!

  5. #5
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Hi dwint,

    Thanks for picking that up. I fixed that up, but unfortunately, that didn't fix my problem.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Hi caracolesa,

    There seem to be something very wrong somewhere, 'cause I don't see the OpenUserFormButton.

    As for :

    When BNCheckButton is clicked, it's not filling the form with pre-existing entries
    do you actually mean, displaying the contents of Column A? If that is the case, you would have to add a ListBox to the Form, and display it with the contents of Column A when the user Clicks on BNCheckButton, and from there the Branch Name can be populated with the Data the user clicked on in the ListBox.

  7. #7
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Hi Winon,

    No, there's nothing wrong in that regard. I have an OpenUserFormButton macro, but there's no button for it on the userform or the spreadsheet. It gets linked to a button on the Excel ribbon. But there's nothing wrong with that part, and in fact, that code is not related to the userform at all. It's completely separate and not affecting anything else.

    As for the BNCheckButton, if you have a look at the Franchise spreadsheet, you will see how each of the buttons work. For instance, open the Franchise spreadsheet, and in the Branch Name text box, type in Brisbane, and then click Branch Name Check. You will see that it searches column A of the spreadsheet, and then fills the userform with the information in that row, so that a user can double check if that's the right record. Clicking on Branch Name Check again will then loop through Column A, searching for any other record with Brisbane in the name (eg, Brisbane City, Royal Brisbane Hospital, etc).

    However, that exact same code does not work in the Leasing spreadsheet. It throws a 1004 error, and I have no idea why.

    Any insight would be greatly appreciated!

  8. #8
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    Just thought I would post the solution here, in case anyone else had the same issue (someone on another forum solved it).

    The button "SignageNeededButton" had a Tag property of 4, and although I can't see how that could affect the FillForm() or SaveForm() functions, when the two are not connected in any way, apparently it did. Apparently 4 can't be used with Columns in code such as:

    Please Login or Register  to view this content.
    Removing that tag property (and ensuring no other controls had that tag property) solved everything, and everything works exactly as it should now.

    Thanks so much for your input, Winon and Dwint!

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SOLVED: Same code in two different sheets, yet 1004 error in one

    Both subs have that exact same code in them.

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Same code in two different sheets, yet doesn't work in one (ARGH!)

    I am very sorry, but I got involved with another issue as well.

    I knew that it could be solved, and I am glad you came right.

  11. #11
    Registered User
    Join Date
    09-11-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: SOLVED: Same code in two different sheets, yet 1004 error in one

    Oh! Hi Norie! Thanks for solving this for me on the other forum. I didn't realise you were over here too.

    I know both subs have the same code, but I just don't understand how a button that's not writing to the database could have any effect on those subs. But I don't understand vba well enough yet.

    In any event, you were absolutely correct, and removing that tag solved everything, so it's all good! I'll wrap my head around why it worked at a later date. Right now, I'm just so happy it's fixed!

    Thanks again! Absolute genius!

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: SOLVED: Same code in two different sheets, yet 1004 error in one

    The button, was it 'Branch Check', called the sub FillForm.

    It doesn't call SaveForm but since that has that same piece of code you would have encountered the same problem there.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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