if statement not working

  • Thread starter Thread starter deb
  • Start date Start date
D

deb

Access 2003 code on forms oncurrent event... I want the below
If DLookup is Admin then
TitleMSP.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True
If DLookup is Admin and Not IsNull(Me.TitleMSP) then
TitleMSP.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True
If DLookup is anything other than Admin then
TitleMSP.Visible = False
ContactUserID.Visible = False
ContactStatus.Visible = False
Label97.Visible = False
Label96.Visible = False
Label95.Visible = True

Here is what I am trying. but it is not working quite right. Thanks in
advance for your help!!

If DLookup("[User_Type]", "[tblVersion]", "[UserID] = '" &
Environ("username") & "'") = "Admin" Then
TitleMSP.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True

If Not IsNull(Me.TitleMSP) Then
TitleMSP.Visible = True
ContactUserID.Visible = True
ContactStatus.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True

Else
TitleMSP.Visible = False
ContactUserID.Visible = False
ContactStatus.Visible = False
Label97.Visible = False
Label96.Visible = False
Label95.Visible = True
End If
End If
 
Oops: Hit Send too soon.

I believe your first End If is in the wrong place. Try:

If DLookup("[User_Type]", "[tblVersion]", _
"[UserID] = '" & Environ("username") & "'") = "Admin" Then
TitleMSP.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True

If Not IsNull(Me.TitleMSP) Then
TitleMSP.Visible = True
ContactUserID.Visible = True
ContactStatus.Visible = True
Label95.Visible = False
Label97.Visible = True
Label96.Visible = True
End If

Else

TitleMSP.Visible = False
ContactUserID.Visible = False
ContactStatus.Visible = False
Label97.Visible = False
Label96.Visible = False
Label95.Visible = True

End If

Incidentally, I always cringe when people use Environ("Username") to get the
current user, because it's trivial to reset its value for the duration of
your use of the Access application. You'd be much better off using the
GetUserName API call, as illustrated in
http://www.mvps.org/access/api/api0008.htm at "The Access Web"
 
else always applies to immediately preceding if

your first if determines 'admin' so last else needs to be matched to that.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
Back
Top