Tweaking required fields

ledmark

Ledmark
Local time
Today, 06:57
Joined
Mar 11, 2008
Messages
127
Hello - I have a form built where the user can enter data, save it and leave if they needs to then come back to it but they cannot print it until all the required fields are completed - the following is the code to accomplish this:


If IsNull(Me.RecruitmentActions) Or IsNull(Me.TimeLeave) Or IsNull(Me.RequestNumberTextField) Or IsNull(Me.AddInfoCall) Or IsNull(Me.PhoneNumber) Or IsNull(Me.ProposedEffDate) Or IsNull(Me.ActionReqBy) Or IsNull(Me.RequestDate) Or IsNull(Me.ActionAuthBy) Or IsNull(Me.To_) Or IsNull(Me.ToPDNumber) Or IsNull(Me.ToPayPlan) Or IsNull(Me.ToOccCode) Or IsNull(Me.ToGradeLevel) Or IsNull(Me.ToNameLocation) Or IsNull(Me.WorkDescriptor) Or IsNull(Me.AppropriationCode) Or IsNull(Me.DutyStation) Or IsNull(Me.RemarksReqOfc) Or IsNull(Me.VICE) Or IsNull(Me.TeleworkIndCode) Then
MsgBox "One or more of the required fields for the RECRUITMENT 52 are empty - Please make sure you have filled out all boxes that are marked required for the RECRUITMENT 52."
Else
Dim stDocName As String

'MsbBox "value=" + RequestNumberTextField

stDocName = "OneRecruitment 52"
DoCmd.OpenReport stDocName, acNormal

End If

My question - someone is asking for the option to fill out three additional fields that are not always needed so they are not marked as required to print. If I add them to the code then no one can print unless they are filled out and they are needed only when a specific type of action is requested.

Is there a way to write code that would allow these extra fields to be added and have the form print even though they are not required? Maybe an If-Then statement - if Not Null then...

Or a different statement just for those fields?

Thank you for any help you can give me in advance.

Laura Edmark
 
Here's a slightly different way to tackle this.

First, for each control on your form that you want to be required, set the tag value for the control to 'Required'. Set the tag value for any optional ones to be 'Optional'

Then, use something like the following (air code) to check to see if the record can be printed:


Code:
Dim ctl as Control
Dim PrintOk as Boolean

PrintOk = True

For Each ctl In Me.Controls   'loop through all the controls on the form and check each one     

If Nz(ctl.Tag,"Optional") = "Required" Then 'if no tag vlaue present, assume it's an optional control
   If IsNull(ctl.Value) then PrintOk = False 'if the control is required and empty, then set the printing flag to false
End if
  
Next ctl

If PrintOk = true then 'if the flag is still true then we're good to go
'code to make the thing print
Else
Msgbox "Fill in the all the required fields dummy", vbinformation
End if

I haven't checked this yet so you may need to do some debugging
 
Why can't you just NOT add them to that IF statement? It appears it is only checking to see if the required fields are NULL, and if any of them are, gives that error message, otherwise opens the report.
 
CraigDolphin - I have to see what a tag value is and how to put it on the required fields and those that are optional.

For the code that you gave me - does that go before the code I have already in place to check for required fields? Does all my code start after "If PrintOk = True then.....
'code to make thing print

I'll have to get into it to figure it out but I'll come back with questions when they pop up. Thank you for your help.

Laura
 
ledmark,

the tag value is a property of the control itself that holds a text string.

You can enter the value via the 'properties' option for the control, or using code like:

Me.ControlName.Tag = "Required"

And the point of my code sample was to replace the code you had. It just makes it easier to read and follow than nested ifs, and if you add more controls/fields in the future, then you don't need to rewrite your code to include the new control. You only have to add it, set the tag value to either required or optional, and it'll work.

And just in case it wasn't clear, the part where I have
'code to make thing print

...you would need to actually replace that bit with the command to print whatever it is you're printing (which is what I assume you're doing when you open the report).


But for the easiest to implement solution, FoFa is entirely correct. If you don't add the new fields to the code you already have, then it won't test to see if those new fields have been filled.
 
Thank you for all your help - I'll play with it and see what i can do.

Laura
 

Users who are viewing this thread

Back
Top Bottom