+ Reply to Thread
Results 1 to 5 of 5

Cancel Problems

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Cancel Problems

    I have a userform with the following code in a Cancel button. The trouble with it is if I make any changes in the text boxes on the userfrom then hit cancel it will save those changes. How can I get it to cancel and not save any changes?



    Private Sub cmdCancel_Click()
        Unload Me
    End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cancel Problems

    that code won't save anything on its own. unless your textboxes are changing the cells as soon as they are changed (either in code or because they are directly bound to the cells) or you have code in the queryclose or terminate events, changes should not be saved.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Cancel Problems

    Thanks Joesph I see the problem now. I use ControlSource in the text box properties to link the cell with the text box so when the form is opened it displays the current information. It updates the cells as I tab from box to box.

    Is there another way of doing this?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cancel Problems

    yeah, you need to use code to populate the textboxes and put the data back in the cells when you click Save (I assume you have a Save button?)
    so like this
    Private sub userform_initialize()
    me.textbox1.value = sheets("sheet name").cells(5, "A").value
    ' repeat for other controls
    End Sub
    
    private sub cmdSave_Click()
    sheets("sheet name").cells(5, "A").value = me.textbox1.value
    ' repeat
    end sub
    and clear the controlsource properties from all the textboxes. usually better to not link controls directly to cells.

  5. #5
    Forum Contributor
    Join Date
    09-08-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    125

    Re: Cancel Problems

    Thanks Joseph that fixed it, I in inserted this line of code and it's all good.

    '   Get Section headings from cell B14
        frmHeadingDetails.txtSecHead.Value = ActiveSheet.Cells(13, 2).Value

+ 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