Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

Checking for empty fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Klein - 03 Mar 2005 18:42 GMT
I need to have a way to check fields for empty before my form moves to a new
record or closes the form.  What is the best event to place the code?
TomU - 03 Mar 2005 19:19 GMT
This covers all situations:

If Len(Nz(Me!MyField, "")) = 0 then
 'Do the blank field processing

TomU

> I need to have a way to check fields for empty before my form moves to a new
> record or closes the form.  What is the best event to place the code?
Jeff Klein - 03 Mar 2005 20:51 GMT
Tom,  Thanks for the reply.  In which event should I use the code?  I need
an event that fires before the record is moved.  I have been experimenting
with different events...no luck.  Any help is appreciated. Jeff

> This covers all situations:
>
[quoted text clipped - 5 lines]
> > I need to have a way to check fields for empty before my form moves to a new
> > record or closes the form.  What is the best event to place the code?
Marshall Barton - 03 Mar 2005 19:26 GMT
>I need to have a way to check fields for empty before my form moves to a new
>record or closes the form.  What is the best event to place the code?

The Form's BeforeUpdate event.

You can set the event procedure's Cancel argument to True to
prevent the form from moving off the current record until
your checks for missing data pass.

Signature

Marsh
MVP [MS Access]

Jeff Klein - 03 Mar 2005 19:47 GMT
Marshall,
Thanks for the reply.  I am confused. Is this what you are describing?  If
so, this does not stop from proceding to the next record.  Maybe I am not
understanding....  wouldn't be the first time.

Private Sub Form_BeforeUpdate(Cancel As Integer)
   DoCmd.CancelEvent
End Sub

> >I need to have a way to check fields for empty before my form moves to a new
> >record or closes the form.  What is the best event to place the code?
[quoted text clipped - 8 lines]
> Marsh
> MVP [MS Access]
Jeff Klein - 03 Mar 2005 19:53 GMT
This is the basic code for checking the field

 If IsNull(txb_Programs) Then
       MsgBox "The Program must be entered", vbOKOnly
       txb_Program.SetFocus
       DoCmd.CancelEvent
       Exit Sub
   End If

> Marshall,
> Thanks for the reply.  I am confused. Is this what you are describing?  If
[quoted text clipped - 18 lines]
> > Marsh
> > MVP [MS Access]
Marshall Barton - 03 Mar 2005 21:53 GMT
Well, that should work, but what I was suggesting was:

If IsNull(txb_Programs) Then
       MsgBox "The Program must be entered", vbOKOnly
       txb_Program.SetFocus
       Cancel = True
       Exit Sub
End If

I try to avoid DoCmd whenever there is an alternative,
because it does not allow you to specify which object it is
supposed to operate on.  In this case, it probably doesn'e
make a lot of difference.

Try it and see if it does what you want.
Signature

Marsh
MVP [MS Access]

>This is the basic code for checking the field
>
[quoted text clipped - 15 lines]
>> > prevent the form from moving off the current record until
>> > your checks for missing data pass.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.