Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I Secure a report 1

Status
Not open for further replies.

chubby

Programmer
Apr 28, 2001
278
US
I have 2 users out of 20 that need to see a report... I'm still having problems with my code. Any suggestions???

Private Sub report_Open(Cancel As Integer)
On Error GoTo ErrFO
If ((CurrentUser() <> &quot;phm2600a&quot;) And (CurrentUser() <> &quot;phm2800b&quot;)) Then
MsgBox &quot;ACCESS DENIED.&quot;
Cancel = True
End If

ExitFO:
Exit Sub

ErrFO:
MsgBox Err.Description, vbInformation, &quot;report Open Error.&quot;
Resume ExitFO
End Sub
 
CurrentUser works only in a secured DB with an MDW file. I'm not sure exactly how the usernames are stored.

If you want the Users NT/Windows Login, use this:

Public Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = &quot;&quot;
End If
End Function
Tyrone Lumley
augerinn@gte.net
 
Isn't there also an environ function that gets the users NT password? Just a thought.

Nick
 
databaseguy, thanks for the code. I'll try it tomorrow and I will let you know if it works or not. Thanks again.

Nickjar, I have code that blocks off different forms from different users. I use built-in secured measures to set read and write permissions. I also use built-in secured to block off unwanted personnel. But I want to do is block a report, you have to use code to do that, it's the only way...
 
Sorry, what i meant was you could use the environ function:

Private Sub report_Open(Cancel As Integer)
dim txtUser as String

txtUser = environ(&quot;username&quot;)

if txtuser = &quot;phm2600a&quot; or txtuser= &quot;phm2800b&quot; then
cancel=true
exit sub
end if

Nick
 
Well I be d***!!! that is petty cool. Nickjar, I'm the one who should be sorry. I had no idea there was even such a thing. (where did you learn this????) I'll try this later on today.. Thanks again, 'Awesome'
 
Someone in work used it and it also got mentioned on here by someone. Pretty easy to use. Not much code.

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top