Invoke form if field meets specific criteria (1 Viewer)

tinyevil777

Registered User.
Local time
Today, 19:58
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
 

spikepl

Eledittingent Beliped
Local time
Today, 20:58
Joined
Nov 3, 2010
Messages
6,144
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
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
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.
 

spikepl

Eledittingent Beliped
Local time
Today, 20:58
Joined
Nov 3, 2010
Messages
6,144
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?
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
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.
 

spikepl

Eledittingent Beliped
Local time
Today, 20:58
Joined
Nov 3, 2010
Messages
6,144
and when you open that handler from the Property Sheet, it is the one you just edited that opens?
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
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
 

spikepl

Eledittingent Beliped
Local time
Today, 20:58
Joined
Nov 3, 2010
Messages
6,144
In the Code Window ->Debug-> Compile do you get any errors?
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
No, no errors are returned when i run the Debug Compile.
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
The control itself is actually on a subform, if that would make any difference?
 

spikepl

Eledittingent Beliped
Local time
Today, 20:58
Joined
Nov 3, 2010
Messages
6,144
Back up your db, and Compact and Repair it. If that does not help then I am out of ideas.
 

tinyevil777

Registered User.
Local time
Today, 19:58
Joined
Dec 10, 2010
Messages
137
Unfortunately that didn't work, thanks for your help though Spike.
 

Users who are viewing this thread

Top Bottom