Re: Microsoft's Answer to DoCmd.Close Bug

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Thanks for the quick answer Ken. I think I can use the nested If..Then
statements to work.

All of the fields, Teacher, Period, Student, and Reason, need to be filled
in on the form. The error message can be general in this case. I want to
use, "Hey idiot, fill in all the fields before you click the close button,
just like is says on the form." But that wouldn't be too PC for the program.

Thanks As Always
Rip


"Ken Snell [MVP]" wrote:

> Can you specify what action should be taken if just one is empty? Do you
> want all to be empty before you'd prompt the user? Or just any one to be
> empty?
>
> One approach could be to use ElseIf..Then statements as additional steps in
> the If..Then block, thus you'd test each field/control individually, and you
> could close the form without saving on any of the tests.
>
> If IsNull(Me![Field1]) Then
> If MsgBox("'Field1' must contain a value." & Chr(13) & Chr(10) & _
> "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
> "Press 'Cancel' to abort the record.", _
> vbOKCancel, "A Required field is Null") = vbCancel Then
> DoCmd.Close
> Else
> Me![Field1].SetFocus
> End If
> ElseIf IsNull(Me![Field2]) Then
> If MsgBox("'Field2' must contain a value." & Chr(13) & Chr(10) & _
> "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
> "Press 'Cancel' to abort the record.", _
> vbOKCancel, "A Required field is Null") = vbCancel Then
> DoCmd.Close
> Else
> Me![Field2].SetFocus
> End If
> ElseIsNull(Me![Field3]) Then
> If MsgBox("'Field3' must contain a value." & Chr(13) & Chr(10) & _
> "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
> "Press 'Cancel' to abort the record.", _
> vbOKCancel, "A Required field is Null") = vbCancel Then
> DoCmd.Close
> Else
> Me![Field3].SetFocus
> End If
> Else
> DoCmd.Close
> End If
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
>
>
>
> "Ripper" <Ripper@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:4AB3F759-70E0-4FEA-8089-FD55883DB5D6@xxxxxxxxxxxxxxxx
> >I was looking in on answer a question without you guys help, SHAME ON ME!!!
> > I discovered the bug where, using the close button DoCmd.Close, does not
> > save
> > if required fields are left empty.
> >
> > I found an answer in the forum that led me to Microsoft's site. Microsoft
> > says to use this code to check if one of your required fields is empty.
> >
> > If IsNull(Me![Field1]) Then
> > If MsgBox("'Field1' must contain a value." & Chr(13) & Chr(10) & _
> > "Press 'OK' to return and enter a value." & Chr(13) & Chr(10) & _
> > "Press 'Cancel' to abort the record.", _
> > vbOKCancel, "A Required field is Null") = vbCancel Then
> > DoCmd.Close
> >
> > Else
> > Me![Field1].SetFocus
> > End If
> > Else
> > DoCmd.Close
> > End If
> >
> >
> > My problem is I have more than one required field on the form and cannot
> > figure out how to make this code check them all. The fields are Teacher,
> > Period, Student, and Reason. How can I edit this code to check them all
> > to
> > see if they are filled in and give me a personal message box for each.
> >
> > Your guys are life savers.
> > --
> > Thanks As Always
> > Rip
>
>
>
.


Quantcast