Results 1 to 9 of 9

Thread: [Resolved]Button Click Event within another

  1. #1

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Resolved [Resolved]Button Click Event within another

    Hi Guys,

    Is it possible to call a Button click even within another button click event?

    Something Like the following

    VB Code:
    1. Private Sub CmdAdd_click()
    2. If Mode = "Edit" then
    3.       CmdMod_click
    4. End If
    5. End Sub
    Last edited by Hack; Sep 29th, 2006 at 06:11 AM. Reason: Added green "resolved" checkmark Last edited by vasanth2979 : Yesterday at 07:05 AM

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Button Click Event within another

    Quote Originally Posted by vasanth2979
    Hi Guys,

    Is it possible to call a Button click even within another button click event?
    Try for it .... it is possible....
    Actually why you are doing like this make a sub or the function for the repeat code

  3. #3
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Button Click Event within another

    Certainly
    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox 1
    3.     Command2_Click
    4. End Sub
    5.  
    6. Private Sub Command2_Click()
    7.     MsgBox 2
    8. End Sub

  4. #4

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: Button Click Event within another

    i actually made a sub and tried to save Data but the prob is the Save function works fine when save button is clicked but not when its corresponding short cut key is pressed( Alt + S)

  5. #5
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Button Click Event within another

    VB Code:
    1. Private Sub CmdAdd_click()
    2. If Mode = "Edit" then
    3.       CmdMod_click
    4. End If
    5. End Sub
    Yes u can call button click event within a button click event. It is the same like you are calling a function within a function.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Button Click Event within another

    Quote Originally Posted by vasanth2979
    i actually made a sub and tried to save Data but the prob is the Save function works fine when save button is clicked but not when its corresponding short cut key is pressed( Alt + S)
    Are you sure the caption on the button is &Save?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  7. #7

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: [Resolved]Button Click Event within another

    Yes I use the same button for Save and Add. If the caption is Add it creates a new row in the table and if caption is save it saves it

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [Resolved]Button Click Event within another

    Are you sure that when you change the caption to Save, you have the '&' in front of the S?

    The following code works for me:
    VB Code:
    1. Private Sub cmd1_Click()
    2. If cmd1.Caption = "&Save" Then
    3.   MsgBox "Save"
    4.   cmd1.Caption = "&Load"
    5. ElseIf cmd1.Caption = "&Load" Then
    6.   MsgBox "Load"
    7.   cmd1.Caption = "&Save"
    8. End If
    9. End Sub
    10.  
    11. Private Sub Form_Activate()
    12. cmd1.Caption = "&Save"
    13. End Sub
    When the button says Save, I can hit it with alt-S, when it says Load, I can hit it with alt-L.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Lively Member vasanth2979's Avatar
    Join Date
    Sep 2006
    Location
    Port Louis, Mauritius
    Posts
    88

    Re: [Resolved]Button Click Event within another

    Thanks Mate,

    I was missing the '&'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width