Click to See Complete Forum and Search --> : User's accounts, passwords and permissions
Roselene
Jan 24th, 2000, 08:15 PM
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
RogerH
Jan 24th, 2000, 09:06 PM
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
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Roger
Roselene
Jan 25th, 2000, 12:04 AM
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
RogerH
Jan 25th, 2000, 12:50 AM
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:
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
Roselene
Jan 25th, 2000, 01:14 AM
Roger,
It works beautifully!
I can check the user name now!
Thanks for helping so much!
See you,
Roselene
Roselene
Jan 25th, 2000, 01:42 AM
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
RogerH
Jan 25th, 2000, 01:58 AM
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
Roselene
Jan 25th, 2000, 11:53 AM
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
Roselene
Jan 25th, 2000, 05:51 PM
Roger,
It was very kind of you helping me that way. I really learnt new commands this time.
thanks a lot
See you,
Roselene
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.