Please help with IF statement (1 Viewer)

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
I have tried several ways of doing this and can not get it to work. Here is the If statement:

Code:
If (Me.ComponentCode = "KM") And (CurrentUser() <> "user1") Or (CurrentUser() <> "user2") Or (CurrentUser() <> "user3") Or (CurrentUser() <> "user4") Then _
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
Me.tblClaims_SSN.SetFocus
End If

I originally had it with out the End If and got an error of saying I need the end if. So I added it now the if statement will not work. It throws the message box everytime.

Do I need to do this as SELECT CASE????

Can someone please help me.
 
Last edited:

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
This all looks rather dynamic so I would recommend you put it in a table and do a dlookup(). What you are doing is called hard-coding. If any of these people change you'll have to go back into your code and make changes...

(Which may not be bad if you're getting paid to come back out and make these type changes ;p)
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
Thanks KenHigg, but I am not sure how to do that.
 
Last edited:

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
So are you going that route or do you still want help ironing out the if thing?
 

MSAccessRookie

AWF VIP
Local time
Today, 11:19
Joined
May 2, 2008
Messages
3,428
I have tried several ways of doing this and can not get it to work. Here is the If statement:

Code:
If (Me.ComponentCode = "KM") And (CurrentUser() <> "cmoratz") Or (CurrentUser() <> "bhoward") Or (CurrentUser() <> "kwilliams") Or (CurrentUser() <> "bwilliams") Then [SIZE=7][B][COLOR=Red]_[/COLOR][/B][/SIZE]
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
Me.tblClaims_SSN.SetFocus
End If
I originally had it with out the End If and got an error of saying I need the end if. So I added it now the if statement will not work. It throws the message box everytime.

Do I need to do this as SELECT CASE????

Can someone please help me.

The following code works for me and is very similar to yours (The names have been changed to protect the innocent clients). They are very similar, except that I see an extra "_" that you have that I do not have.

-----------------------------------------------------------------------

If ((Me.UserName = "SQLDevelopment") Or (Me.UserName = "User1") Or (Me.UserName = "User2")) Then
Me.TransactionsButton.Visible = True
Me.MerckOrdersReport.Visible = True
End If
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
Thanks MSAccessRookie, I will try it.

KenHiggs, I would like to learn your way as well. Since I have several of these per form.
 

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
I think he simply needs to put parens around all of his 'or' stuff so at least one of the 'or's are true (If that's the logic).

???
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
Compile Error: End If without If Block

Code:
If (Me.CompCode = "KM") And ((CurrentUser() <> "cmoratz") Or (CurrentUser() <> "bhoward") Or (CurrentUser() <> "kwilliams") Or (CurrentUser() <> "bwilliams")) Then _
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
Me.tblClaims_SSN.SetFocus
End If
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
I did that also, but now it gives me the MsgBox and that shouldn't happen.
 

MSAccessRookie

AWF VIP
Local time
Today, 11:19
Joined
May 2, 2008
Messages
3,428
Based on the timing of th post, I am guessing you did not see my last reply. try getting rid of the "_" at the end of the first line
 

MSAccessRookie

AWF VIP
Local time
Today, 11:19
Joined
May 2, 2008
Messages
3,428
Break the sentence down and answer two questions please.

1. What is the value of Me.CompCode?
2. What is your active CurrentUser()?
 

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
I think you have a rouge 'if' else where in your code - ?
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
I have removed the "_" and now it gives me the MsgBox and It shouldn't.

Code:
If (Me.CompCode = "KM") And ((CurrentUser() <> "User1") Or (CurrentUser() <> "User2") Or (CurrentUser() <> "User3") Or (CurrentUser() <> "User4")) Then
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
End If



1. CompCode is text and can either be null or KM
2. CurrentUser() = cmoratz

KenHigg - what do u mean by a Rogue 'if' Else in my code?
 
Last edited:

MSAccessRookie

AWF VIP
Local time
Today, 11:19
Joined
May 2, 2008
Messages
3,428
I have removed the "_" and now it gives me the MsgBox and It shouldn't.

Code:
If (Me.CompCode = "KM") And ((CurrentUser() <> "User1") [B][COLOR=Red]Or [/COLOR][/B](CurrentUser() <> "User2") [COLOR=Red][B]Or [/B][/COLOR](CurrentUser() <> "User3") [B][COLOR=Red]Or [/COLOR][/B](CurrentUser() <> "User4")) Then
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
End If
1. CompCode is text and can either be null or KM
2. CurrentUser() = cmoratz

I think I see at least one point. I think that you want And instead of Or in all of the Red marked locations. Also:

1. I need to know what it IS, not what it COULD BE (to determine Pass/Fail for this part).
2. User cmoratz is not in the list of allowed users { User1; User2; User3; and User4 }.
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
KenHigg - how do you do the Dlookup that you were talking about?
 

Bigmo2u

Registered User.
Local time
Today, 10:19
Joined
Nov 29, 2005
Messages
200
The code really looks like this:

Code:
If (Me.CompCode = "KM") And ((CurrentUser() <> "cmoratz") Or (CurrentUser() <> "bhoward") Or (CurrentUser() <> "kwilliams") Or (CurrentUser() <> "bwilliams")) Then
MsgBox "You are not authorized to enter this claim. Please take it to MCRATS."
Me.tblClaims_SSN.SetFocus

End If

CompCode = KM
CurrentUser = cmoratz

Sorry for the confusion. Not sure on the "And" part you pointed out. If the compcode is is KM and it is right now and not equal to any of these user then throw the msgbox and setfocus on the SSN field.

If the compcode = KM and it is one of the users listed to do nothing.
 
Last edited:

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
I think you simply need to replace all of you 'or's with 'and's...
 

KenHigg

Registered User
Local time
Today, 11:19
Joined
Jun 9, 2004
Messages
13,327
My bad, I see Rookie already suggested that - :)
 

Users who are viewing this thread

Top Bottom