Cryptic compile error

R

requeth

I'm getting the error message:

"Compile error: Function call on left-hand side of assignment must
return Variant or Object"

I am attaching my module below, it is selecting the MsgBox line when I
choose ok after the error. I do not see anything wrong, but I have no
idea what the help file is talking about. Does anyone see what the
issue is?

Option Compare Database

Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No

sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK
Private Sub AppExit_Click()
Application.Quit acPrompt
Else
DoCmd.OpenForm "MainMenu"

End Sub
 
M

Marshall Barton

I'm getting the error message:

"Compile error: Function call on left-hand side of assignment must
return Variant or Object"

I am attaching my module below, it is selecting the MsgBox line when I
choose ok after the error. I do not see anything wrong, but I have no
idea what the help file is talking about. Does anyone see what the
issue is? [snip]
MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK


As the error message indicates, assigning a value to the
result of a function call is a pretty tricky thing to do.

Perhaps you meant it to be a comparison in an If statement?
 
R

requeth

Ok, I have adjusted my code, my main problem now is I'm trying to make
it so when someone clicks the OK button on the mesgbox that it will run
AptExit_Click. To compile it is requiring an = to the right of the
MsgBox(strMsg, vbOKOnly, "Access Error"). How would I attach the
AppExit_Click function onclick? Updated code is below. I have it
commented out right now so the code will compile.

Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function AppExit_Click()
Application.Quit acPrompt
End Function
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No
End If
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
'MsgBox(strMsg, vbOKOnly, "Access Error")

Else
DoCmd.OpenForm "MainMenu"
End If

End Function
'End Sub



There's a couple of things you have in there that don't make sense to me.
The first is:

MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK

You're trying to assign a value to a function call, which is givng you that
error message you mentioned. You should leave out the '= vbOk' part. I'm not
sure why you have that there. Byspecifying VbBOKnly in the msgbx call it will
only show that option.

The 2nd problem is you have:

....
Private Sub AppExit_Click()
Application.Quit acPrompt
Else
DoCmd.OpenForm "MainMenu"

You're defining the AppExit_Click Sub in the middle of an If Then statement!
I'm not sure what you;re intent is with that part of thecode but that
shouldn't compile successfully either.



I'm getting the error message:
"Compile error: Function call on left-hand side of assignment must
return Variant or Object"
I am attaching my module below, it is selecting the MsgBox line when I
choose ok after the error. I do not see anything wrong, but I have no
idea what the help file is talking about. Does anyone see what the
issue is?
Option Compare Database
Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK
Private Sub AppExit_Click()
Application.Quit acPrompt
Else
DoCmd.OpenForm "MainMenu"
End Sub- Hide quoted text -- Show quoted text -
 
D

Douglas J. Steele

Since you're not giving them any choice but OK (you're using vbOKOnly as a
parameter), you don't need to check what's returned by the function.

That means you can use

MsgBox strMsg, vbOKOnly, "Access Error"
Call AppExit_Click

If you were giving them a choice, you could use something like:

Select Case MsgBox(strMsg, vbOKCancel, "Access Error")
Case vbOK
Call AppExit_Click
Case Else
End Select



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ok, I have adjusted my code, my main problem now is I'm trying to make
it so when someone clicks the OK button on the mesgbox that it will run
AptExit_Click. To compile it is requiring an = to the right of the
MsgBox(strMsg, vbOKOnly, "Access Error"). How would I attach the
AppExit_Click function onclick? Updated code is below. I have it
commented out right now so the code will compile.

Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function AppExit_Click()
Application.Quit acPrompt
End Function
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No
End If
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
'MsgBox(strMsg, vbOKOnly, "Access Error")

Else
DoCmd.OpenForm "MainMenu"
End If

End Function
'End Sub



There's a couple of things you have in there that don't make sense to me.
The first is:

MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK

You're trying to assign a value to a function call, which is givng you
that
error message you mentioned. You should leave out the '= vbOk' part. I'm
not
sure why you have that there. Byspecifying VbBOKnly in the msgbx call it
will
only show that option.

The 2nd problem is you have:

....
Private Sub AppExit_Click()
Application.Quit acPrompt
Else
DoCmd.OpenForm "MainMenu"

You're defining the AppExit_Click Sub in the middle of an If Then
statement!
I'm not sure what you;re intent is with that part of thecode but that
shouldn't compile successfully either.



I'm getting the error message:
"Compile error: Function call on left-hand side of assignment must
return Variant or Object"
I am attaching my module below, it is selecting the MsgBox line when I
choose ok after the error. I do not see anything wrong, but I have no
idea what the help file is talking about. Does anyone see what the
issue is?
Option Compare Database
Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
MsgBox(strMsg, vbOKOnly, "Access Error") = _
vbOK
Private Sub AppExit_Click()
Application.Quit acPrompt
Else
DoCmd.OpenForm "MainMenu"
End Sub- Hide quoted text -- Show quoted text -
 
M

Matthias Klaey

To compile it is requiring an = to the right of the
MsgBox(strMsg, vbOKOnly, "Access Error").

There are two ways to call a Sub or Function.
The first is *without* parentheses:

MsgBox strMsg, vbOKOnly, "Access Error"

Using parentheses in this case gives a compile error.

The second is with the keyword Call and *with* parentheses:

Call MsgBox(strMsg, vbOKOnly, "Access Error")

Leaving out the "Call" keyword also gives a compile error.

HTH
Matthias Kläy
 
R

requeth

That did it, thank you everybody! I'm posting the completed code that
compiles below in the event someone finds it useful later.

Option Compare Database

Public Declare Function apiLogOut Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function AppExit_Click()
Application.Quit acPrompt
End Function
Function auditlog() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
Dim v_user As String
Dim Authorized As Boolean
Dim Authload
Dim strMsg
strUserName = String$(254, 0)
lngLen = 255
lngX = apiLogOut(strUserName, lngLen)
If lngX <> 0 Then
auditlog = Left$(strUserName, lngLen - 1)
Else
auditlog = "No ID"
End If
v_user = auditlog
Authload = "SELECT COUNT(*) FROM PTEAM WHERE FXID='" & v_user & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL Authload
DoCmd.SetWarnings True
If Authload = 1 Then
Authorized = Yes
Else
Authorized = No
End If
sqlInsertStatement = "Insert into
UserLog([UserName],[LoginDate],[LoginTime],[StatusType],[Authorized])
Values('" & v_user & "','" & Format(Date, "mm\/dd\/yyyy") & "','" &
Time & "','Logout','" & Authorized & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL sqlInsertStatement
DoCmd.SetWarnings True
If Authorized = No Then
strMsg = "Access is not permitted. Please speak with the process team
leader for further guidance."
MsgBox strMsg, vbOKOnly, "Access Error"
Call AppExit_Click

Else
DoCmd.OpenForm "MainMenu"
End If

End Function
'End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top