+ Reply to Thread
Results 1 to 14 of 14

help with calling a function (B) and return control of program flow to the calling functio

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    help with calling a function (B) and return control of program flow to the calling functio

    Can anyone help with calling a function (B) and return control of program flow to the calling function (A)?

    These functions are in different modules of the same workbook's VBE.

    The modules contain only those functions.

    Ideally, control would return to function (A) at the point where function (B) was called after function (B) does its work.

    I guess it would work like a gosub...return.

    Here's why:

    The code to locate a value (from an input box) in a column (C) has been written but this code has to be run for each task the user will perform, (ie: new entry, delete entry, edit entry, etc.);

    All tasks are accomplished through some sort of dialogue box (msgbox, inputbox and/or userform), there is no direct entry into a cell.

    Each task is different enough to require its own code but they all require finding an inputted value in col. C to begin to determine where the task is to take place.

    So is anyone that can help?

    Quick reply to this message Reply Reply With Quote Reply With Quote Multi-Quote This Message

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: help with calling a function (B) and return control of program flow to the calling fun

    I don't 100% follow what you are asking here, but sounds like you want to start one procedure, jump to another, and then return to the first procedure.

    If so,

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    I hav'nt, as yet, tried your code but I think I need something more like:

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 10-19-2012 at 09:22 PM.

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Notice the difference between the code I posted and yours, please follow the forum rules and use code tags.

  5. #5
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Quote Originally Posted by jeffreybrown View Post
    Notice the difference between the code I posted and yours, please follow the forum rules and use code tags.

    Jeffery,

    Sorry

    Fairly new to the forum but I already knew this so no excuse.
    Will try to remember in the future.

    Here it is in the correct format.

    John


    I haven't, as yet, tried your code but I think I need something more like:

    Please Login or Register  to view this content.
    Last edited by john/nyc; 10-19-2012 at 09:06 PM.

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: help with calling a function (B) and return control of program flow to the calling fun

    John,

    What have you tried so far and/or do you already have code your working with?

  7. #7
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Jeff,

    I don't have code that addresses this problem, but if you're wondering what I'm trying to do have a look here:

    http://www.excelforum.com/hello-intr...ways-lost.html

    It explains what is bring attempted.

    here is the code that would be called

    Please Login or Register  to view this content.
    Notice that there is a call near the bottom of this code.

    This call (AppointmentDate) calls another routine that has the user input a date for a new appointment. But if the code above is used find the Apartment number in order to cancel an appointment I don't know how to give control to the cancel appointment procedure or the edit appointment procedure.

    Copy and paste the majority of this code for each new procedure doesn't seem appropriate.

    I could be wrong, I've been wrong before

    John
    Last edited by john/nyc; 10-20-2012 at 12:24 AM. Reason: mistake

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Hi John,

    This is quite the project.

    I might be able to drive to Round Rock, pick a few things up at IKEA, and drive back before I could come up with a good solution.

    Without seeing the entire project and using some trial and error, I don't have a good solution; however, I do have a suggestion.

    Build a user form. With a user form, you should be able to pull up a record, edit and save or even delete.

    Contextures

    Build a UserForm for Excel - Fontstuff

  9. #9
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Jeff,

    Thanks for the suggestion.

    It's like the guy whose tooth ache goes away in the dentist's waiting room: I've come up with a couple of ideas that I'm going to try first.

    Either way, whether I River Walk my own way through this or try your suggestion, if anything works then I'll come back and post it.

    Later,

    John

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

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Just a comment on the original post - if you call a sub/function from another sub/function then once the called sub/function has completed control will return to the calling sub/function.

    So there's no need to tell the code to return to the calling sub/function.

  11. #11
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Norie,

    Thanks for the tip.

    John
    Last edited by Cutter; 10-21-2012 at 07:38 PM. Reason: Removed whole post quote

  12. #12
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Jeff,

    I think I found a solution. It involves a public variable.

    I'll let u know.

    John

  13. #13
    Registered User
    Join Date
    08-17-2012
    Location
    Round Rock, Tx
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Quote Originally Posted by john/nyc View Post
    Jeff,

    Thanks for the suggestion.

    It's like the guy whose tooth ache goes away in the dentist's waiting room: I've come up with a couple of ideas that I'm going to try first.

    Either way, whether I River Walk my own way through this or try your suggestion, if anything works then I'll come back and post it.

    Later,

    John
    Jeff,


    It was a poorly asked question.

    1) The calling function is a user form with 7 option buttons in a frame that is launched from workbook_open. Each button launches a different task (enter new appointment, cancel existing appointment, edit existing, etc.). Don't want to return there.

    2) The called function is code that locates an apartment number after error checking. This code, itself, ends with a call to another function the allows the user to input(box) an appointment_date. Then the appointment_date function calls the appointment_time function which calls the doctor's_name function , and so on.

    3) This was dandy as long as all that was being done was to enter a new appointment, but what if cancel_appointment was the chosen task? The code to enter a date wasn't needed but code to find a date had to be found and plagiarized.

    4) But locating an apartment number was needed in all the tasks. Initially it was just copy_paste the apt. locate code at the beginning of the all the code no matter the task. Didn't think that was the way to go even though it worked.

    5) What was actually needed was a way to send flow from the apt. num. function to the next function dependent on which task option was selected in the initial user form.


    What I wound up doing was declaring a public variable at the tippy_top of this_workbook. Then, in the user form code, giving that variable a different value to correspond to the chosen task. Then testing that value at the end of the apt. num. code in order to send control to the appropriate function. It also became handy for changing the prompts in a msgbox to reflect the task at hand.

    I'm sorry that you had to waste your time answering a dysfunctional question. I'll try, in the future, to think things more thoroughly through.

    Thanks again,

    John

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: help with calling a function (B) and return control of program flow to the calling fun

    Quote Originally Posted by john/nyc View Post
    I'm sorry that you had to waste your time answering a dysfunctional question. I'll try, in the future, to think things more thoroughly through.
    No need to be sorry John. Sometimes the best way to get your task solved is by asking questions until the light bulb goes off in your head, because in the end, you know your project better than anyone else

    ----------------------------------------------------------------------------------------------------------------

    Thanks for the feedback and...

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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