Results 1 to 9 of 9

Thread: User's accounts, passwords and permissions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Hi, folks!

    I'm working with a VB Project which deals with a MS Access Database.

    I'd like to create some users names and passwords, in order to identify each user everytime he/she starts the program and to control his/her access to some parts of the it.

    Where should I create these accounts? Access or VB? When the user clicks a button on a form, the button "Delete record", for example, is there a way to check the user's name before VB proceeds the action?

    Please, point me the right direction.
    Thanks in advance,
    Roselene

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi,

    I dont't now, if you can add users by SQL command in Access but in SQL Server / MDAC you can.

    To get the username in Windows use
    Code:
    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Roger

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Smalig,

    sorry, but I'd like to ask you some questions. This example is for VB, isn't it?

    Would this example allow me to deal with users' accounts inside VB, independent from the Windows users?

    Thanks for helping,
    :-) Roselene

  4. #4
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi Roselene,

    1.) Put the declare statement in a module (not form or class). If you declare it as public, you can use it anywhere in you program.
    Attention id you're not familiar with WinAPI programming: You have to reserve space for the result that comes in the lpBuffer variable!

    Here is some code for a general function. Put it in a code module:

    Code:
    Option Explicit
    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Public Function CurrentUserName() As String
    
        Dim strVar As String
        strVar = Space(255)
        GetUserName strVar, 255
        strVar = Left$(strVar, InStr(strVar, Chr(0)) - 1)
        CurrentUserName = strVar
    
    End Function

    2.) I think I can answer the question to smalig too: This example works with DAO (data access objects) in VB (works in Access too) and adds a user to the database you are already connected with.

    Roger

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Roger,

    It works beautifully!
    I can check the user name now!

    Thanks for helping so much!
    See you,
    Roselene

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Roger,

    Only if it won't disturb you, could you, please, give me any further information on how do the following lines work?
    It's already working perfectly, I'd just like to understand these commands.

    ...
    GetUserName strVar, 255
    strVar = Left$(strVar, InStr(strVar, Chr(0)) - 1)
    ...

    Thanks again,
    ;-) Roselene

  7. #7
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Sure Roselene, any time!

    The API-function GetUserName wants 2 parameters: A buffer (with reserved room, that's the reason for the SPACE(255)) and the max length of that buffer.
    It returns the result in the buffer, terminated with character 0 (usual in C, API is mostly written in C).
    You have to find the terminating character 0 and get all the characters before it. That's what the line

    Left$(strVar, InStr(strVar, Chr(0)) - 1)

    does.

    Roger



  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Roger,

    Where should I add the line you have sent me?
    I've tried several places, always receiving error messages.
    This line would allow me to know the windows current user's name using VB, would't it?

    Yes, I have a lots to learn...

    Thanks for helping,
    :-) Roselene

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Itabirito,Minas Gerais, Brazil
    Posts
    79

    Post

    Roger,

    It was very kind of you helping me that way. I really learnt new commands this time.

    thanks a lot

    See you,
    Roselene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width