Avatar billede plato Juniormester
15. marts 2014 - 09:14 Der er 10 kommentarer og
1 løsning

Oprette globalt modul for database

Hej alle.

Jeg har et Module1 i min database:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

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 = vbNullString
    End If
End Function
Function fldIsEmpty(fld As Variant)

    If IsNull(Len(Trim(fld))) Then
    'If IsNull(fld) Or fld = "" Or IsNull(Len(fld)) Then
        fldIsEmpty = True
    Else
        fldIsEmpty = False
    End If
   
End Function

Jeg har ikke selv skrevet koden men bare copy/paste.

Nu vil jeg gerne at jeg kan tjekke om admin=true på nogle forskellige forms når brugeren benytter dem.

Tabellen hedder tblEmploy og indeholder:
EmpId (Autonumber)
Init
Fname
Lname
Admin (Yes/No)

Er der én der kan hjælpe mig til koden for det?
Avatar billede terry Ekspert
15. marts 2014 - 11:41 #1
Nu vil jeg gerne at jeg kan tjekke om admin=true på nogle forskellige forms når brugeren benytter dem.


Can you explain what you mean by that?
fOSUserName is giving you network user name, is that not what you want?
Avatar billede plato Juniormester
15. marts 2014 - 11:55 #2
Ohh. I want a global check where fOSUsername = Init (from tblEmploy) AND Admin = True then u have access.

It's no problem for me to bind a form to a query that do just that. But if I have a form that is bound to another query, I want a global function. One I perhaps could use in "on load".

Make sense?
Avatar billede terry Ekspert
15. marts 2014 - 12:32 #3
If you have a menu system which you use to open the different forms then you could have a check in the on click event



If fOSUserName() = Dlookup(.... Then

open your from

Else

...
Avatar billede terry Ekspert
15. marts 2014 - 12:33 #4
AND Admin = True ???

where does admin come from?
Avatar billede terry Ekspert
15. marts 2014 - 12:36 #5
also from table?

if so then use dcount a


If Dcount("*", "tblEmploy", "Init = '" & fOSUsername & "' AND Admin = True") > 0 Then


...
Avatar billede plato Juniormester
15. marts 2014 - 12:37 #6
Admin comes from tblEmploy just like Init and is a True/False field.

Surpose I could use DLook. Going to take at that.
Avatar billede plato Juniormester
15. marts 2014 - 12:40 #7
A look at that.....
Avatar billede plato Juniormester
15. marts 2014 - 12:42 #8
Ok, I will use that solution. I just thought it could be done Global so that you just called a function like "SecurityCheck". :-)
Avatar billede terry Ekspert
15. marts 2014 - 13:14 #9
just thought it could be done Global so that you just called a function like "SecurityCheck". :-)

It can if that's what you want but you still have to write a line of code each time you want to check ...
Avatar billede plato Juniormester
15. marts 2014 - 13:19 #10
Yeah. You are right about that. :-) Above works great. Ty. :-)
Avatar billede terry Ekspert
15. marts 2014 - 15:47 #11
selv tak
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester