-
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
-
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
-
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.
----------------------
-
Seaweed,
Thanks for taking the time for helping me.
I'll give it a try!
See you,
Roselene
-
You can also use a boolean, if it's only to detect if you need to add a new record or not