Save User Information

  • Thread starter Russ via AccessMonster.com
  • Start date
R

Russ via AccessMonster.com

What I need to do is have a log in form that I can store and use the user ID
number of the person logged in.
Example
When Jane (ID#3) logs in it will store that Jane (ID#3) logged in at 7:30 AM
into a table, then what ever form she opened it would automatically use her
user ID number until she logged out. We do not want to have the user keep
selecting / entering their name on the form, want it to be automatic. Home I
am explaining this well enough??

Thanks in advance!
 
M

Metra

Let me see if I understand your process -- you have a table of users, each
of which is assigned a unique identifier... you're not using a database
secured with a non-System MDW or an ADP which is using integrated
security...

If that's the case, probably the easiest thing is to have a database
property, perhaps called "myUserID", populated it when she logs on, and
empty when she logs off.

Below are two functions you can use to do this...Add them to a standard
module (If you don't have a reference to DAO, you'll need to add one):

To use:
call the SetCustomProperty function when she logs in.

Example: SetCustomProperty("myUserID",dbtext, cStr(UserID))

Whenever you want to get the number, call GetCustomProperty. You can use it
in queries or where-ever.

Example: GetCustomProperty("myUserID").

When you shut the application down, call the SetCustomProperty again,
setting the value to some invalid string, like a single space,
"N/A","LoggedOff", whatever.

'-----------Start Code Block-----------
Function SetCustomProperty(strPropName As String, intPropType _
As Integer, strPropValue As String) As Integer

Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property
Const conPropertyNotFound = 3270 ' Property not found error.

Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set doc = cnt.Documents!UserDefined ' Define Document object.
On Error GoTo SetCustom_Err
doc.Properties.Refresh
' Set custom property name. If error occurs here it means
' property doesn't exist and needs to be created and appended

' to Properties collection of Document object.
If strPropName = "" Then GoTo SetCustom_Bye Else
Set prp = doc.Properties(strPropName)
prp = strPropValue ' Set custom property value.
SetCustomProperty = True

SetCustom_Bye:
Exit Function

SetCustom_Err:
If Err = conPropertyNotFound Then
Set prp = doc.CreateProperty(strPropName, intPropType, strPropValue)
doc.Properties.Append prp ' Append to collection.
Resume Next
Else ' Unknown error.
SetCustomProperty = False

Resume SetCustom_Bye
End If
End Function


Function GetCustomProperty(strPropName As String) As String
Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property

' Property not found error.
Const conPropertyNotFound = 3270

On Error GoTo GetCustomProperty_Err
Set dbs = CurrentDb
Set cnt = dbs.Containers!Databases
Set doc = cnt.Documents!UserDefined
doc.Properties.Refresh
GetCustomProperty = doc.Properties(strPropName)

GetCustomProperty_Bye:
Exit Function

GetCustomProperty_Err:
If Err = conPropertyNotFound Then
Set prp = doc.CreateProperty(strPropName, dbtext, "None")
' Append to collection.
doc.Properties.Append prp
Resume
Else
' Unknown error.
GetCustomProperty = ""
Resume GetCustomProperty_Bye
End If
End Function

'-----------End Code Block-----------
 
R

Russ via AccessMonster.com

Wow, thanks I will give it a try!
Let me see if I understand your process -- you have a table of users, each
of which is assigned a unique identifier... you're not using a database
secured with a non-System MDW or an ADP which is using integrated
security...

If that's the case, probably the easiest thing is to have a database
property, perhaps called "myUserID", populated it when she logs on, and
empty when she logs off.

Below are two functions you can use to do this...Add them to a standard
module (If you don't have a reference to DAO, you'll need to add one):

To use:
call the SetCustomProperty function when she logs in.

Example: SetCustomProperty("myUserID",dbtext, cStr(UserID))

Whenever you want to get the number, call GetCustomProperty. You can use it
in queries or where-ever.

Example: GetCustomProperty("myUserID").

When you shut the application down, call the SetCustomProperty again,
setting the value to some invalid string, like a single space,
"N/A","LoggedOff", whatever.

'-----------Start Code Block-----------
Function SetCustomProperty(strPropName As String, intPropType _
As Integer, strPropValue As String) As Integer

Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property
Const conPropertyNotFound = 3270 ' Property not found error.

Set dbs = CurrentDb ' Define Database object.
Set cnt = dbs.Containers!Databases ' Define Container object.
Set doc = cnt.Documents!UserDefined ' Define Document object.
On Error GoTo SetCustom_Err
doc.Properties.Refresh
' Set custom property name. If error occurs here it means
' property doesn't exist and needs to be created and appended

' to Properties collection of Document object.
If strPropName = "" Then GoTo SetCustom_Bye Else
Set prp = doc.Properties(strPropName)
prp = strPropValue ' Set custom property value.
SetCustomProperty = True

SetCustom_Bye:
Exit Function

SetCustom_Err:
If Err = conPropertyNotFound Then
Set prp = doc.CreateProperty(strPropName, intPropType, strPropValue)
doc.Properties.Append prp ' Append to collection.
Resume Next
Else ' Unknown error.
SetCustomProperty = False

Resume SetCustom_Bye
End If
End Function

Function GetCustomProperty(strPropName As String) As String
Dim dbs As Database, cnt As Container
Dim doc As Document, prp As Property

' Property not found error.
Const conPropertyNotFound = 3270

On Error GoTo GetCustomProperty_Err
Set dbs = CurrentDb
Set cnt = dbs.Containers!Databases
Set doc = cnt.Documents!UserDefined
doc.Properties.Refresh
GetCustomProperty = doc.Properties(strPropName)

GetCustomProperty_Bye:
Exit Function

GetCustomProperty_Err:
If Err = conPropertyNotFound Then
Set prp = doc.CreateProperty(strPropName, dbtext, "None")
' Append to collection.
doc.Properties.Append prp
Resume
Else
' Unknown error.
GetCustomProperty = ""
Resume GetCustomProperty_Bye
End If
End Function

'-----------End Code Block-----------
What I need to do is have a log in form that I can store and use the user ID
number of the person logged in.
[quoted text clipped - 6 lines]
Thanks in advance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top