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
Microsoft AccessMicrosoft ApplicationsMicrosoft Office
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
mbizup
Can you post a sample database?
gigifarrow
ASKER
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
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
Dale Fye
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.
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.
Dale Fye
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).Then, 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.
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