Option box

Nej

New member
Local time
Today, 17:09
Joined
Jul 15, 2002
Messages
8
Hello. I hope someone can help me or point me in the right direction to get help. Here is my problem:

I have a form, frmNewWorkOrder that has an option box on it. The option box has two options, "Pending" and "Complete". The values for the options (Pending = 1, Complete = 2) are stored in the Worder table in the WorkOrderStatus field. When a user clicks on "Complete" I want to run code (I have this code already) that validates certain fields on the form before it will let the user go to the next record. And if the user selects the "Pending" option it allows them to leave the record with out validating the fields.

So my question is how do I get the form to run the code to validate the fields only when the "Complete" option is selected?

Thank you for any help.
 
In the AfterUpdate event of the Option Box...

If OptionBox = 2 then
'Code to validate fields
Else
'Code to exit without validating
End If
 
Its still not working. Here is what I have so far.

Private Sub WorkOrderStatus_AfterUpdate()
'Field validation when a work order record is marked as complete
If WorkOrderStatus = 2 Then

If IsNull(Me.Descrip) Then
MsgBox "Description is a required field."
Me!Descrip.SetFocus
Cancel = True
Else

If IsNull(Me.From) Then
MsgBox "Location is a required field."
Me!From.SetFocus
Cancel = True
End If
End If
Else
Resume
'I'm not sure if that is right either but even without it, it still doesn't work

End If

When I run this it gives a "variable not defined error" for cancel. And if I put in Cancel as Integer in the parentheses it brings up another error about code that has nothing to do with the option box. I know the other code works fine with out the new code for the option box so I don't think thats it either. Sorry, I'm pretty new at this :) Thanks
 
Thanks for the help. I had someone here at work look at it too and we renamed the option box and put the code in the Before Update event so now it works.

Here is the only part we changed:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Field validation when a work order record is marked as complete
If Me.optWorkOrderStatus = 2 Then
.
.
.
.


Thanks again!
 

Users who are viewing this thread

Back
Top Bottom