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 / General 2 / May 2007

Tip: Looking for answers? Try searching our database.

Required Field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Secret Squirrel - 26 May 2007 02:41 GMT
I have a field on my form that is required for all new records created. This
is the code I have in the BeforeUpdate event on my form.

Private Sub Form_BeforeUpdate(Cancel As Integer)
  If IsNull(Me.RequestedBy) Then

     MsgBox "You Must Select Your Name!"
     
     Cancel = True

     Me.RequestedBy.SetFocus

  End If

End Sub

It doesn't seem to be working properly. Right now if I created a new record
and didn't fill in that field and just clicked the close button on my form I
do get the msgbox but then the form closes. Am I missing something here? It
doesn't set the focus on that field the way it's written in the code. I also
have this field flagged as required in the table. What am I doing wrong?
John W. Vinson - 26 May 2007 04:52 GMT
>I have a field on my form that is required for all new records created. This
>is the code I have in the BeforeUpdate event on my form.
[quoted text clipped - 17 lines]
>doesn't set the focus on that field the way it's written in the code. I also
>have this field flagged as required in the table. What am I doing wrong?

Did you actually *create a new record* - by dirtying some *other* field? If
not, then the BeforeUpdate event will not fire, because there's nothing to
update. You're just opening a blank, uninitialized record and then closing it.

If you did in fact enter data into some other field, then there's clearly
something wrong - more details please!

            John W. Vinson [MVP]
 
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.