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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeforeUpdate Event 2

Status
Not open for further replies.

jbehrne

Programmer
Dec 18, 2002
484
US
Hi All,

I am having some problem with this bit of code. I have a BeforeUpdate event that checks to see if a check box is checked. If the check box is checked and a textbox does not have any text then an error message is displayed letting the user know to enter a value. However, if the user unselects the check box (leaving the textbox blank) the beforeupdate will not allow the user to move to another record until the screen is refreshed... Any ideas on how to get this code to work correctly? Thanks,

jbehrne

Code:
Private Sub Form_BeforeUpdate(cancel As Integer)
Me.Check75.SetFocus
If (Me!Check75.Value = True) Then
    Me!FSOrderNumber.SetFocus
    If Trim(Me!FSWorkOrderNumber.Text) = "" Then
        MsgBox "A valid MRO number is required.", vbOKOnly + vbCritical, "Missing Data - Enter MRO"
        cancel = True
    End If
Else
    cancel = False
End If
    
End Sub

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
How about...

Private Sub Form_BeforeUpdate(cancel As Integer)
Me.Check75.SetFocus
If (Me!Check75.Value = True) Then
Me!FSOrderNumber.SetFocus
If Trim(Me!FSWorkOrderNumber.Text) = "" Then
MsgBox "A valid MRO number is required.", vbOKOnly + vbCritical, "Missing Data - Enter MRO"
cancel = True
End If
cancel = True
Else
cancel = False
End If

End Sub


Randy
 
You could try Me.Recalc in the AfterUpdate of the checkbox...

Ken S.
 
How are ya jbehrne . . . . .

. . . and this:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   
   If Me!Check75 Then
      If Trim(Me!FSWorkOrderNumber & "") = "" Then
         Msg = "A valid MRO number is required."
         Style = vbOKOnly + vbCritical
         Title = "Missing Data - Enter MRO"
         MsgBox Msg, Style, Title
         Cancel = True
      End If
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks for everyone's help! Eupher's method of having the recalc worked great.

jbehrne

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Actually - Eupher's method seemed to work fine - unless the user selected/unselected the checkbox twice (without entering a value in the textbox). However, TheAceMan1's code actually did work w/o any problems! Thanks again,

jbehrne

If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top