admin button module help

gmc2k2

Registered User.
Local time
Today, 00:41
Joined
Oct 7, 2008
Messages
21
hi all,

I need some help with some code i have, i have a button where if the user is an admin (in a table) it opens a form if they're a user it pops up a message box, the problem i'm having is if the user hasn't had any details put in the table it opens the form anyway.

i'm using the fosusername function to dlookup the table but i want a message popping up if the user isn't on the table yet.

Private Sub openadmin_Click()
If DLookup("Group", "tblUsers", "Username =""" & fOSUserName & """") <> "Admin" Then
MsgBox "You have insufficient rights to open the Admin Form"
Else: DoCmd.OpenForm "users", acFormDS
End If

End Sub

any help appreciated
 
Something like..
Code:
Private Sub openadmin_Click()
    [COLOR=Red][B]Dim userStr As String
    userStr = Nz([/B][/COLOR]DLookup("Group", "tblUsers", "Username =""" & fOSUserName & """")[COLOR=Red][B], "No Rights")[/B][/COLOR]
    [COLOR=Red][B]Select Case userStr
        Case "Admin"[/B][/COLOR]
            DoCmd.OpenForm "users", acFormDS
        [COLOR=Red][B]Case "No Rights"[/B][/COLOR]
            MsgBox "You have insufficient rights to open the Admin Form"
        [COLOR=Red][B]Case Else
            MsgBox "This is where you will open a User form"
    End Select[/B][/COLOR]
End Sub
 
works like a charm :) thank you so much AGAIN paul :) means a lot
 
Sorry i've cleaned it up slightly now paul to this:
Code:
Private Sub openpipeline_Click()
Dim strEmailreg As String
Dim userStr As String
Dim oApp As Outlook.Application
Dim oMail As MailItem

userStr = Nz(DLookup("Group", "tblUsers", "Username =""" & fOSUserName & """"), "User")
    Select Case userStr
        Case "Admin"
            DoCmd.OpenForm "Customer", acNormal
        Case "User"
            DoCmd.OpenForm "Customer", acNormal
        Case Else
        MsgBox("You are not registered, would you like to email details to register?", vbYesNo, "Registration") = vbYes
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
oMail.Body = "Body of the email"
oMail.Subject = "Registration Details"
oMail.To = "Someone@somewhere.com"
oMail.Show
Else
End If
    
Set oMail = Nothing
Set oApp = Nothing
End Select
End Sub
but getting a Compile error: Function call on left hand side of assignment must return variant or object
 

Users who are viewing this thread

Back
Top Bottom