Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make a Subform Field Required

Posted on 2012-12-30
10
Medium Priority
?
993 Views
Last Modified: 2013-01-01
I Have a form that is in a  tab format.

One of the tab pages is a subform. On save I have some fields  that are required before it will save. I need it to also  make fields  required on the subform but the code is not working.
Any experts know what im doing wrong? here is the code:
 
(frmInductionChecks) is the name of the subform.
(frmMain)is the name of the main form.
(Date of Induction) is the name of the control.

 If IsNull(Me!frmInductionChecks.Form![Date of Induction]) Then
  MsgBox "You must provide a value for Perform Date of Induction."
  Me.Me!frmInductionChecks.Form![Date of Induction].SetFocus
     Cancel = True
     Exit Sub
 End If


 If IsNull(Me.Text562) Then
     MsgBox "You must provide a value for Perform Fire Turret Runout Reading."
     Me.Text562.SetFocus
     Cancel = True
     Exit Sub
 End If
0
Comment
Question by:gigifarrow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1000 total points
ID: 38731520
Where is your code located?

Put it in the BeforeUpdate event of the main form if it is not there already.  Also your subform reference is not quite correct.  Try this:

 If "" & Me.frmInductionChecks.Form.[Date of Induction] = "" Then
  MsgBox "You must provide a value for Perform Date of Induction."
  Me.frmInductionChecks.Form.[Date of Induction].SetFocus
     Cancel = True
     Exit Sub
 End If


 If "" & Me.Text562 = "" Then
     MsgBox "You must provide a value for Perform Fire Turret Runout Reading."
     Me.Text562.SetFocus
     Cancel = True
     Exit Sub
 End If

Open in new window

0
 

Author Comment

by:gigifarrow
ID: 38731601
My code is on save record that is where all the append quieries are .
It will not append unless all these field are filled up.

if I put it on before update it will allow the user to contintinue. and still save the record.

 when i put it on save  button it wont save until the fields are field out.


thank you for the help and your time I will try this.


The message pops up I hit okay but it will not let you fill in the blank I have it on before update like u said
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38731673
Can you post a sample database?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:gigifarrow
ID: 38731983
That is okay it is working fine , but how could i do it so i dont have to write every control down in a subform?

Dim ctl As Control
    For Each ctl In Me.Controls
       If IsNull(ctl) Then
           MsgBox ctl.Name & " Is Empty, Please enter a Value.", vbCritical
           'Controls(ctl.Name).SetFocus
           Exit Sub
        End If
  ' Next ctl
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38732159
For each ctl in Me.subformname.form.controls

Etc...
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1000 total points
ID: 38732441
1.  recommend you adopt the syntax that mbizup used to test whether the control is empty.  Your syntax will only identify those that are null, not those that are an empty string "".  By concatenating an empty string to the controls value, and testing to see if the result is still an empty string, you will identify both NULLs and empty strings.

2.  And if you have some fields in the subform that are not required, then one technique is to add something to the Tag property of the controls that are (I set Tag to "Req"), then modify the loop to include a check for the Tag property

3.  Lastly, I have not checked all versions of Access, but some will not allow you to directly set the focus to a control on a subform without first setting the focus to that form, so I added a line for that as well
Dim ctl As Control
    For Each ctl In Me.subformControlName.Controls
       If ("" & ctl.Value  = "") AND (ctrl.Tag = "Req") Then
           MsgBox ctl.Name & " Is Empty, Please enter a Value.", vbCritical
           me.subformcontrolName.form.setfocus
           me.subformcontrolname.form.controls(ctrl.Name).SetFocus
           Exit Sub
        End If
  Next ctl 

Open in new window

0
 

Author Comment

by:gigifarrow
ID: 38733974
I tried what you said fyed but when i push save it doesnt work . I get no error message

Dim ctl As Control
    For Each ctl In Me.subformControlName.Controls
       If ("" & ctl.Value  = "") AND (ctrl.Tag = "Req") Then
           MsgBox ctl.Name & " Is Empty, Please enter a Value.", vbCritical
           me.subformcontrolName.form.setfocus
           me.subformcontrolname.form.controls(ctrl.Name).SetFocus
           Exit Sub
        End If
  Next ctl  



This code works:

 If "" & Me.frmInductionChecks.Form.[Date of Induction] = "" Then
  MsgBox "You must provide a value for Perform Date of Induction."
  Me.frmInductionChecks.Form.[Date of Induction].SetFocus
     Cancel = True
     Exit Sub
 End If

I would rathe r use the first one so that I dont have to write each field. Here is my database I had to delete alot of it
sendinhelprestriction.zip
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38734394
try changing:

    For Each ctl In Me.subformControlName.Controls

to

    For Each ctl In Me.subformControlName.Form.Controls

Have you put a breakpoint in the code and stepped through it?  That is almost always the first step in debugging why something is not doing what you expect it to do.
0
 

Author Comment

by:gigifarrow
ID: 38734653
No i didnt put a code to stepped through dont know how.

 I have been assigned to do access and I have only taken one class and that wasnt in depth. I will try this thank you.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38734743
gigi,

To create a breakpoint in your code, you open a code module and then left-click in the bar that runs from top to bottom, just to the left of the code window.  When you do this, you will see a red/brown dot appear in that bar (see attached).breakpointThen, when you run your application, when the code reaches the line that is highlighted by the dot, it will pause and display the code window.  You can then mouse over the code and see the values of the controls and variables in your code.  You use the F8 button to "step-through" your code, one line at a time. You can use the F5 button to resume your code execution when you are done stepping through the code.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question