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 / August 2005

Tip: Looking for answers? Try searching our database.

Required Field at subform level

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gg - 02 Aug 2005 18:09 GMT
I have a check box field in my Main form called "PO_flag."  On my subform, I
have a field called "PO_no".  If the PO_flag field is "checked" (="Y"), the
PO_no field on the subform must be required (filled in).  If not, the message
will be MsgBox "You must enter a PO#."  I put the following code in the
Before Update Event procedure but nothing happens.  Do I also need code in
the subform under the PO_no field?

Private Sub Check161_BeforeUpdate(Cancel As Integer)  

If Me!PO_flag = "Y" Then
   MsgBox "You are required to enter a Purchase Order # in the line-item
detail section."
   Me!PO_flag.SetFocus
   Cancel = True
End If

End Sub

Thank you!
Allen Browne - 03 Aug 2005 10:25 GMT
Use the BeforeUpdate event of the *form*, not the check box. The event for
the check box will not fire unless the user does something with it.

So you will need something like this in the BeforeUpdate event of the
subform:

Private Sub Form_BeforeUpdate(Cancel As Integer)
   If Me.Parent!PO_flag.Value Then
       If IsNull(Me.PO_no) Then
           Cancel = True
           MsgBox "PO_no required..."
       End If
   End If
End Sub

Note that a checkbox has the value True or False, which is not the same as
the text "Y".

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I have a check box field in my Main form called "PO_flag."  On my subform,
>I
[quoted text clipped - 18 lines]
>
> Thank you!
 
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.