Here is what I came up with. Its really cheesy and I would like something a little more secure
Code:
Private Sub Form_Open(Cancel As Integer)
Dim pwd As String
pwd = InputBox("What is the Password?")
If pwd = "TC" Then
MsgBox "Success!!"
Else
MsgBox "That was incorrect. Please try again"
DoCmd.CLOSE
End If
End Sub
So I googled and found there was a way to get logged in user.
So I have this module built as GetUserName
Code:
Option Compare Database
Declare Function WNetGetUser Lib "mpr.dll" _
Alias "WNetGetUserA" (ByVal lpName As String, _
ByVal lpUserName As String, lpnLength As Long) As Long
Const NoError = 0 'The Function call was successful
Function GetUserName() As String
Dim LUserName As String
Const lpnLength As Integer = 255
Dim status As Integer
Dim lpName
' Assign the buffer size constant to lpUserName.
LUserName = Space$(lpnLength + 1)
' Get the log-on name of the person using product.
status = WNetGetUser(lpName, LUserName, lpnLength)
' See whether error occurred.
If status = NoError Then
' This line removes the null character. Strings in C are null-
' terminated. Strings in Visual Basic are not null-terminated.
' The null character must be removed from the C strings to be used
' cleanly in Visual Basic.
LUserName = Left$(LUserName, InStr(LUserName, Chr(0)) - 1)
Else
' An error occurred.
MsgBox "Unable to get the name."
End
End If
GetUserName = LUserName
End Function
Now, How do I call that function and return the string value on the form load event or form open event?
I tried this.
dim stname as string
stname = GetUserName()
Msbbox stname
This doesn't work. Very new to VBA.
Thanks in advance