required field IIF

D

Donny

On my form I have a field that is a Combo Box (1,2,3,None) If None is not
picked I want another field (Estimated Total Field Hours) to be required.
Fairly new user.
Thanks in advance!
 
L

Linq Adams via AccessMonster.com

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.ComboBoxName = "None" And IsNull(Me.[Estimated Total Field Hours]) Then
Cancel = True
MsgBox "With ComboBox Set to 'None' Estimated Total Field Hours must be
filled in!"
Me.[Estimated Total Field Hours].SetFocus
End If
End Sub
 
D

Donny

Thanks, I'm alot closer now. I modified the code slightly to return a not
equal to "None" but I'm receiving a " Run time error '2108' You must save the
field before you execute the SetFocus method" Her is my modified code. Any
suggestions would be appreciated.
Thanks
Private Sub Priority_BeforeUpdate(Cancel As Integer)
If Me.Priority <> "None" And IsNull(Me.[Estimated Total Field Hours]) Then
Cancel = True
MsgBox "If Priority is a 1,2 or 3 then 'Estimated Total Field Hours' must
be filled in!"
Me.[Estimated Total Field Hours].SetFocus
End If

End Sub
 
L

Linq Adams via AccessMonster.com

I'm sorry,I misread the thing about 'None!'

The problem is that you've put the code in the ***control's*** BeforeUpdate
event! Validation code that checks for required data has to go in the
***form's*** BeforeUpdate event!

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Priority <> "None" And IsNull(Me.[Estimated Total Field Hours]) Then
Cancel = True
MsgBox "If Priority is a 1,2 or 3 then 'Estimated Total Field Hours' must
be filled in!"
Me.[Estimated Total Field Hours].SetFocus
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top