How to show a messagebox on null textbox or wrong data??

R

Ron

I have this code that inserts whatever is in txtGrade into an
enrollment table.

DoCmd.SetWarnings False


would I just insert code that said:
if txtgrade "" then
msgbox "Enter all grades"
else
DoCmd.OpenQuery "querytoinsertgrade"

What if I wanted to make sure the grades were either A, B, C, D, or F
and nothing else, so if something other than those was entered in
txtgrade I would get a textbox that said that all grades are not right
and to redo them??

how would I do something like this?
 
D

Douglas J. Steele

If Len(Me.txtGrade & "") = 0 Then
MsgBox "Enter all Grades"
Else
Select Case Me.txtGrade
Case "A", "B", "C", "D", "F"
DoCmd.OpenQuery "querytoinsertgrade"
Case Else
MsgBox "Invalid Grade"
End Select
End If

On the other hand, if you're trying to limit the input, why not use a combo
box rather than a text box?
 
Top