+ Reply to Thread
Results 1 to 6 of 6

Calling validation method before saving

  1. #1
    Registered User
    Join Date
    12-30-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Calling validation method before saving

    Hello

    I have a piece of codes that I wanted it to be run before saving. However, I do not know how to call the method that contains the validation codes in the BeforeSave event handler. I am super bad at coding macro, please help me.

    Attached below is the sample file that I did to show what am I doing. The codes are inside the sample file.
    Sample2.xlsm

    I thought of using a function method so that I could have a return value to indicate whether to allow save or cancel saving. However, I am stuck as I do not know how to call the method in a way that I could check if the method returns a False, I will allow save. Else, if the method returns a True, I will cancel saving.

    Please help me.
    Last edited by potato; 01-29-2012 at 10:08 PM.
    Cheers,
    Pauline the potato

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Calling validation method before saving

    something like:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-30-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calling validation method before saving

    Hi kyle,

    Do you mind explaning what does that line of code "If Not checksaved Then" actually do? Is the "checksaved" refering to the variable that I used to store the return result?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Calling validation method before saving

    It directly calls your function, if your function returns false then it won't save the workbook. If it returns true, then the workbook will be saved

  5. #5
    Registered User
    Join Date
    12-30-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calling validation method before saving

    Is it correct to say that the "Not" keyword is refering to False?

    And I realised that I need to change one of the cell's value right before the saving is done. So I tried modifying the codes you have given. But when I test run it, multiple msgbox came popping out, all coming from the same result. I assumed that the validation method was called a few times. How can I solve this problem?

    Below is the modified codes.
    Please Login or Register  to view this content.
    Thanks so much for your help Kyle. (:

  6. #6
    Registered User
    Join Date
    12-30-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Calling validation method before saving

    Quote Originally Posted by potato View Post
    Is it correct to say that the "Not" keyword is refering to False?

    And I realised that I need to change one of the cell's value right before the saving is done. So I tried modifying the codes you have given. But when I test run it, multiple msgbox came popping out, all coming from the same result. I assumed that the validation method was called a few times. How can I solve this problem?

    Below is the modified codes.
    Please Login or Register  to view this content.
    Thanks so much for your help Kyle. (:
    Hi Kyle,

    I have solved my problem with the following codes:
    Please Login or Register  to view this content.
    Once again, thank you for your help! (:

+ 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