View Full Version : Help with If Then Else statement


cooh23
04-16-2008, 06:24 PM
Good Evening Everyone,

I am having a problem getting this code below to work

Private Sub btnAdminTools_Click()
On Error GoTo Err_btnAdminTools_Click

If admin = True _
Then
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmallinonereport"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Else
MsgBox "You Do Not Have access to this Form"
Exit_btnAdminTools_Click:
Exit Sub

Err_btnAdminTools_Click:
MsgBox Err.Description
Resume Exit_btnAdminTools_Click
End If

End Sub

Basically, what i am trying to do is when a user who is not classified as an admin should get the error "You do not have access to this form", if they are admin, then they can open it.

Thank you,

ajetrumpet
04-16-2008, 07:53 PM
Private Sub btnAdminTools_Click()
On Error GoTo Err_btnAdminTools_Click

If admin = True _ <--- What is this referring to? A check box?So, you are trying to check a boolean type control? Is that what's hanging you up on this?

cooh23
04-16-2008, 08:07 PM
So, you are trying to check a boolean type control? Is that what's hanging you up on this?

Hi. Thank you for looking at this. I got it to work now. But here's what i am doing.

I have a module that looks into a table to see if my username (my windows login called by environ("username")) is an admin under Roles in the table). If not, then to give me an error box. I actually didn't change anything in the code I provided. I just had to compile the code and compact the database. For whatever reason, it worked.

Thank you