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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Argument not Optional

Status
Not open for further replies.

corbinap

Programmer
Nov 20, 2006
34
US
I am getting a compile error on this line in my code below... I am trying to assign approval levels depending on currentuser who is loged or signed into database.

<< If Val(Me.ProjectedTotal & "") + Val(Me.ProjectedTotal & "") < ApprovalAmount(CurrentUser) Then>> Highlighting "Approvalamount " saying that the Argument is not optional.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

If Val(Me.ProjectedTotal & "") + Val(Me.ProjectedTotal & "") = 0 Then
MsgBox "Forecast Must Be Entered"
Else
'If strManagerType = "EVP" Then
If CurrentUser = "EVP" Then
MsgBox "Approved"
Else
If Val(Me.ProjectedTotal & "") + Val(Me.ProjectedTotal & "") < ApprovalAmount(CurrentUser) Then
MsgBox "Approved"
Else
MsgBox "Amounts Cannot Be Approve

Function ApprovalAmount(strManagerType As String, TotalCost As Long) As Boolean
Dim ApprovalLimit As Long
Dim rst As New ADODB.Recordset


''Set rst = CurrentProject.Connection.Execute("SELECT tblUsers.UserID " & _
"FROM tblusers " & _
'"WHERE (tblUsers.UserID)='" & [CurrentUser] & "'")


Select Case currentuser
Case "SM"
ApprovalLimit = 300000
Case "DIR"
ApprovalLimit = 1500000
Case "VP1"
ApprovalLimit = 3000000
Case "EVP"
CanApprove = True
Exit Function
End Select
CanApprove = (TotalCost < ApprovalLimit)
End Function
 
Hello,
Code:
Function ApprovalAmount(strManagerType As String, TotalCost As Long) As Boolean
Your function is expecting 2 arguments, ManagerType and TotalCost. You are only supplying the first one in your code. Good Luck!
 
10doesch

It would be a better design if you create a table of approval limits for each manager. Then use DLookup statement on this table or the recordset
Code:
ApprovalLimit = DLookup("ApprovalLimit", "tblApprovals", "UserID'="[CurrentUser]&"'")

tblApprovals
Field :UserID
DataType:Text
Field :ApprovalLimit
DataType:Currency

Avoid hard coded values for variables that change outside the code!
 
As stated the ApprovalAmount function returns true or false...and takes two arguements: user and amount...so the line:

If Val(Me.ProjectedTotal & "") + Val(Me.ProjectedTotal & "") < ApprovalAmount(CurrentUser) Then

should read

If ApprovalAmount(CurrentUser, (Val(Me.ProjectedTotal & "") + Val(Me.ProjectedTotal & ""))) Then

The ApprovalAmount code here is more like the last clode example in thread705-1301482 versus the code example I supplied.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top