Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing value

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Please advise how I could save this Get Name value? I would like to store name value of people using the database but dont know how to get this to work?

[tt]
Private Declare Function apiGetLoginName Lib "advapi32.dll" Alias _
"GetLoginName" (ByVal lpBuffer As String, nSize As Long) As Long

Function FGetName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetLoginName(strUserName, lngLen)
If lngX <> 0 Then
FGetName = Left$(strUserName, lngLen - 1)
Else
FGetName = &quot;&quot;
End If

'here you can add the code to save the value of FGetName into the
table[/tt]

End Function
 
Well, that all depends on where you're calling the code from.

The easy way is to have a form BOUND to the table that you want to store the into in.
Then on the Form you have a control BOUND to the field where the data is to go.
Then once you're sure that you're on the right record - in the code set
ControlName = FGetName

job done.


However, if that can't work then just open a recordset on the Table at the appropriate record and set:-
rst!FieldName = FGetName
rst.Update
rst.Close

( Code for defining and opening recordsets is dependent on DAO or ADO usage )


'ope-that-'elps.

G LS
 
Firstly, try this
Code:
Environ(&quot;USERNAME&quot;)[\code] instead of the Api call to get the username. I use this on NT4 and it works fine but I'm not sure about other platforms. 

Anyway, to your real question. I have a similar thing in a db I wrote. I have a table with users that have permission to use the system (they are kicked out immediately if they are not in the table). One of the fields in the table is a flag to say whether the user is logged in or not. I have a form that opens when the database starts and only closes when the db is shut down. So, in the load event of the form I set the 'LoggedIn' flag in the Users table to true and in Unload event of the form I set it back to false. This way I can tell exactly who is logged in at any time. 
I don't think this is exactly what you are trying to do but I hope it gives you some ideas.;-) Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top