Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Event Triggers a Macro

Status
Not open for further replies.

DSerr77

Technical User
Jul 21, 2004
42
US
I need help! I am trying to have the change in a cell value trigger the running of a macro. I am not concerned about what the value changes to, just that it changes. Thanks for any help.
 
Something like this should work. If you do not want this to happen on a new record:

Private Sub YourFieldName_LostFocus()

If Not Me.NewRecord And (Me.YourFieldName.Value <> Me.YourFieldName.OldValue) Then
Docmd.RunMacro "YourMacro"
End If

If want it to happen on all records, whether new or old:

Private Sub YourFieldName_LostFocus()

If Me.YourFieldName.Value <> Me.YourFieldName.OldValue Then
Docmd.RunMacro "YourMacro"
End If




The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
Hi there!
Are we possibly talking about the change event for a cell in Microsoft Excel?
change in a cell value ...

If that is the case, then you want:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    [!]YourMacroNameHere[/!]
End Sub

Hope this helps.

Tom

Born once die twice; born twice die once.
 
Incidentally, the macro you call from the above event should be posted as a Public Sub like this:

Code:
[COLOR=blue]Public Sub[/color] [!]YourMacroNameHere[/!]
     [COLOR=green]'Do something[/color]
[COLOR=blue]End Sub[/color]

Hope this helps.
Tom

Born once die twice; born twice die once.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top