Before Update

Lyncroft

QPR for ever
Local time
Today, 21:19
Joined
May 18, 2002
Messages
168
I've got 2 separate option groups connected to 2 separate text boxes.

In each case when the option value is 2 the text box must be filled in before proceeding to the next record. This works fine for the first option group and text box, but it ignores the second option group message when I go to the next record. Any ideas?

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.FrameImported = 2 And IsNull(txtCountry) Then
MsgBox "You must enter a country"
Cancel = True
If Me.FrameModified = 2 And IsNull(txtModified) Then
MsgBox "You must enter a description"
Cancel = True
End If
End If
End Sub
 
Try this:


If Me.FrameImported = 2 And IsNull(txtCountry) Then
MsgBox "You must enter a country"
Cancel = True
Exit sub
else
'do nothing
end if

If Me.FrameModified = 2 And IsNull(txtModified) Then
MsgBox "You must enter a description"
Cancel = True
exit sub
Else
'do nothing
End If

End Sub
 
Hello Elana

Tried that but didn't work either. Still misses the second message.
The user gets a message on each option group when it's selected so they do get a warning - can't do everything for them I guess!

Thanks again
 
If Me.FrameImported = 2 And IsNull(Me.txtCountry) Then
MsgBox "You must enter a country"
Cancel = True
end if

If Me.FrameModified = 2 And IsNull(Me.txtModified) Then
MsgBox "You must enter a description"
Cancel = True
End If

End Sub
 
(I submitted this simultaneously with Rich I guess - we both have the same answer though)

I tested this and it works perfectly.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.frImported = 2 And IsNull(Me.txtCountry) Then
MsgBox "You need to enter a country"
Cancel = True
Exit Sub
ElseIf Me.frModified = 2 And IsNull(Me.txtModified) Then
MsgBox "You need to enter a description"
Cancel = True
Exit Sub
Else
' do nothing, update the record
End If

End Sub

If the user hasn't entered anything in frModified, then it won't check txtModified ... likewise with frImported. So be sure you deal with making sure all the fields are filled in before the procedure checks for the value.

Also, check to be sure you are using numeric fields for frImported and frModified - if they are not numeric, add code that deals with having an empty string vs. a null value in those fields.
 
Last edited:
At last got it!!!

Not too sure why it wasn't working but having reread both of your advice with a clear head this morning I've got it to work. Really ought to learn to call it a day when the head starts spinning.

Cheers again.
 

Users who are viewing this thread

Back
Top Bottom