Results 1 to 5 of 5

Thread: The button clicked before...

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post

    Here is another way to implement netSurfer's first idea, only instead of using a global variable, use the Save button's Tag property.

    I have found the Tag property to be very useful (especially in control arrays where all controls have the same name and are only differentiated by an index).

    Simply set the Tag property (which is a string) of the Save button to the caption of the last button clicked. Do this under the click event of the NewRecord button and the Changes button.

    Here's an example:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    
        'Make sure tag is empty when form loads
        cmdSave.Tag = ""
        
    End Sub
    
    Private Sub cmdChanges_Click()
    
        cmdSave.Tag = "Changes"
        
    End Sub
    
    Private Sub cmdNewRecord_Click()
    
        cmdSave.Tag = "NewRecord"
        
    End Sub
    
    Private Sub cmdSave_Click()
    
        If cmdSave.Tag = "Changes" Then
            'Put code here that reflects that user
            'clicked the "Change" button
            
        ElseIf cmdSave.Tag = "NewRecord" Then
            'Put code here that reflects that user
            'clicked the "New Record" button
        
        Else
            'Put code here that reflects that user
            'didn't click either button first
            
        End If
        
    End Sub
    Hope that helps!

    ~seaweed

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Hi, everybody!

    Is there a way I can use to find out what of two buttons was the last one to be clicked?

    I've got a button for "Changes" and a button for "New record" and I'd like my button "Save" to act with some little differences, deppends on the button clicked before.

    Any ideas on how to control this?

    Thanks in advance,
    Roselene


  3. #3
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    quick way:

    dim strBtn as string

    in the General Declarations of your form

    whne click changed button:

    strBtn = "Changed"

    when New

    strBtn = "New"


    for the Saved button:

    if strBtn = "Changed" then
    elseif strBtn = "New"


    Or you could change the caption on the button. When they change a record, you're actually opdating it so changethe Caption to "Update" then in the Saved button's Click event do:

    if cmdSaved.caption = "Update" then
    'do changed routine
    else
    'do new routine.
    end if

    Either way would work.

    ------------------
    ----------------------
    I'm really easy to get along with once you people learn to
    worship me.
    ----------------------

  4. #4
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Seaweed,

    Thanks for taking the time for helping me.
    I'll give it a try!

    See you,
    Roselene

  5. #5
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    You can also use a boolean, if it's only to detect if you need to add a new record or not

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