Invoke form if field meets specific criteria

tinyevil777

Registered User.
Local time
Today, 20:31
Joined
Dec 10, 2010
Messages
137
Good morning all,

I have a field called "BookingStatuslbl". When the word "Cancelled" is entered into this field, i want a macro to run that will open a form to enter a Cancellation reason in.

I've entered the following code into the AfterUpdate event for the "BookingStatuslbl" field, but it doesn't do anything, it just tabs to the next field.

Code:
Private Sub BookingStatuslbl_AfterUpdate()
   If Me.BookingStatuslbl = "Cancelled" Then
       DoCmd.RunMacro "CancForm", acNormal
   End If
End Sub


Any help/pointers would be greatly appreciated, thank you in advance!


Cheers,

Tom
 
Relying on manual entry in this situation is not a good idea. You probably have more than this one status, so you should use a combobox to let user select a status from a list instead of typing.

What Control type is BookingStatuslbl ?

Code:
Private Sub BookingStatuslbl_AfterUpdate()
   [COLOR=Red]debug.print "Booking status is " & Me.BookingStatuslbl [/COLOR]
   If Me.BookingStatuslbl = "Cancelled" Then 
       [COLOR=Red]debug.print "Calling the macro " [/COLOR]
       DoCmd.RunMacro "CancForm", acNormal    
    End If 
End Sub
Insert the red lines and inspect the value in the Immediate Window (below the code window) . If you see both lines, then your macro may be faulty
 
The control type is a Text Box, but validation on the control restricts users to entering only three options - Confirmed, Awaiting Confirmation or Cancelled.

I inserted the red lines as you said, nothing was displayed in the Immediate Window. I then saved, re-tested and it's still the same.

My macro is quite literally displayed a MsgBox with the word Success in, so the error won't/shouldn't be there.
 
It is not a good idea to force users to type anything, if it can easily be made selectable from a list, Especially if you save that status somewhere

So your event handler does not get called. When you look at the Property Sheet -> Events , do you see your handler there in After Update?
 
Yes, the handler is there as an Event Procedure for After Update. I've double checked the naming of the controls, and it all matches perfectly. Can't think any other debug.
 
and when you open that handler from the Property Sheet, it is the one you just edited that opens?
 
Yep, the code is

Code:
Private Sub BookingStatuslbl_AfterUpdate()
   Debug.Print "Booking status is " & Me.BookingStatuslbl
   If Me.BookingStatuslbl = "Cancelled" Then
       Debug.Print "Calling the macro "
       DoCmd.RunMacro "CancForm", acNormal
    End If
End Sub
 
In the Code Window ->Debug-> Compile do you get any errors?
 
The control itself is actually on a subform, if that would make any difference?
 
Back up your db, and Compact and Repair it. If that does not help then I am out of ideas.
 
Unfortunately that didn't work, thanks for your help though Spike.
 

Users who are viewing this thread

Back
Top Bottom