variable holding 2 values for multiple users

Corticus

Well-known Member
Joined
Apr 30, 2002
Messages
1,579
Hi all,

Will Access assign two different values to the same variable for two users?

Say you have a form, and the form set a variable to a value. If someone else is using the db, and they set that variable to a different value (both users are using the db at the same time), will the variable hold 2 values, one for each user, at the same time?

Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Why wouldn't you just split the db so each user his own form? I know it doesn't address the question, I'm just curious.
 
Upvote 0
Thanks for the reply Dugantrain,

I figured out a better way. I can just use Wingetusername() every time I need to test the users permissions, and just have the results of Wingetusername() query a table of permissions for that user.

Thanks!
 
Upvote 0
Where did you find that? That seems much easier than the dozens of lines of code I usually see people post to get a handle on user/login info.
 
Upvote 0
My bad,

Great API, forget where I got it:

Code:
Option Compare Database

Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

Private Const NO_ERROR = 0
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Global thisuser As String

Function WinUsername() As String

Dim strBuf As String, lngUser As Long, strUn As String
strBuf = Space$(255) '//Clear buffer
lngUser = WNetGetUser("", strBuf, 255)
If lngUser = NO_ERROR Then
strUn = Left(strBuf, InStr(strBuf, vbNullChar) - 1)
WinUsername = strUn
Else
WinUsername = "Error :" & lngUser
End If

End Function

Here's some of the stuff I did in the form that uses it, I won't try to explain it all, but you might be interested:

objects:
FrmLogin
TblLogin
CmdCancel
CmdSavePW
TxtPassword
TxtConfirm
TxtUserLogin
Code:
Option Compare Database

Private Sub CmdCancel_Click()

If Me.Dirty Then
    Me.Undo
    DoCmd.Close
Else
    DoCmd.Close
End If

End Sub

Private Sub CmdSavePW_Click()

If IsNull(TxtPassword) Then
    Me.Undo
    Exit Sub
End If

If TxtConfirmPW <> TxtPassword Then
    Me.Undo
    MsgBox ("Please make sure passwords match")
    TxtConfirmPW = ""
Else
    If Me.Dirty Then Me.Dirty = False
End If

End Sub

Private Sub Form_Load()

TxtUserLogin = WinUsername()

' Find the record that matches the control.
    Dim sql As String
    Dim rs As Recordset
    Dim db As Database
    Set db = CurrentDb()
    
    sql = "SELECT TblLogIn.LoginName, TblLogin.Password " & _
          "FROM TblLogIn " & _
          "WHERE TblLogIn.LoginName=" & _
          """" & TxtUserLogin.Value & """" & ";"

    Set rs = db.OpenRecordset(sql)
        
    If rs.EOF Then
        MsgBox ("Welcome, " & TxtUserLogin & Chr(10) & _
        "No Record...you must be new!")
        Me.RecordSource = "TblLogin"
        DoCmd.GoToRecord , , acNewRec
        TxtLoginName = TxtUserLogin
    Else:
        Set Me.Recordset = rs
        rs.MoveFirst
    End If

End Sub

Enjoy, it seems to work like a champ...I hate wizards...
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top