Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to use sub/function 2

Status
Not open for further replies.

BabyPowder2u

Programmer
May 4, 2005
87
US
I want to use a sub to verify entry of required fields, if it fails I want to exit the main sub.
All the fields mentioned in the check_Required are on the form.

I am getting a "compile error: Expected Function or Variable"
on the "AllRequired = check_Required" line

my code is:

Private Sub cmdScheduleRequest_Click()
Dim AllRequired As Boolean

AllRequired = check_Required
If Not AllRequired Then Exit Sub
.
.
.
End sub

Sub check_Required()
Dim AllRequired As Boolean

If "((IsNull(cboDtSubmitted)) or (IsNull(cboSubPOC)) " & _
"or (IsNull(cboStartDate1)) or (IsNull(cboStartHour1)) or (IsNull(cboEndDate1)) " & _
"or (isnull(cboEndHour1)))" Then
AllRequired = False
Else
AllRequired = True
End If
End Sub

Can someone please help me understand what I've done wrong?

Thanks,
T
 
Function check_Required() As Boolean
If IsNull(cboDtSubmitted) Or IsNull(cboSubPOC) _
Or IsNull(cboStartDate1) Or IsNull(cboStartHour1) _
Or IsNull(cboEndDate1) Or IsNull(cboEndHour1) Then
check_Required = False
Else
check_Required = True
End If
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
1) You've set the value of your boolean variable to the value of a subroutine, but the subs don't return a value. Make check_Required a function instead.

2) Your check_Required doesn't return a value. Instead it looks like you're trying to set the value of AllRequired from within check_Required. Here the scope of your variables is actually helping you - or at least not letting you get into trouble. If AllRequired were exposed throughout your form's module as your code implies, you would have the same variable being declared in multiple locations and the compiler would surely bark at you. Eliminate the Dim statement in check_Required and (since you've now changed it to a function and it can return a value) change "AllRequired =" to "check_Required =". Should work then.

In fact, the AllRequired variable is unnecessary. You could just say "If Not check_Required Then..."

HTH,

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top