|
-
Mar 11th, 2000, 09:13 PM
#1
Thread Starter
Lively Member
I'm using this code to write who's logged onto a workstation to a databse. When they log off, it should record "Logged off".
The problem is, it leaves the old record and when it writes the new one, it missed the username and puts "Logged off" on a record of it's own
I can't seem to work out the edit command.
Any ideas?
Simon
Private Sub Form_Unload(Cancel As Integer)
'write to Who's On file
Dim dbs As Database, rstwhosOn As Recordset
Set dbs = OpenDatabase("user.mdb")
Set rstwhosOn = dbs.OpenRecordset("whosOn")
rstwhosOn.MoveFirst
Do Until rstwhosOn.EOF
If rstwhosOn!workstationName = CurrentComputername Then
rstwhosOn.Delete
End If
rstwhosOn.MoveNext
Loop
rstwhosOn.AddNew
rstwhosOn!workstationName = CurrentComputername
rstwhosOn!UserName = "Logged off"
rstwhosOn.Update
rstwhosOn.Close
dbs.Close
End Sub
-
Mar 13th, 2000, 08:31 AM
#2
Addicted Member
Hi there,
Have hard time try to analyze it. But try then anyway..
Private Sub Form_Unload(Cancel As Integer)
Set dbs = OpenDatabase("user.mdb")
Set rstwhosOn = dbs.OpenRecordset("select * from whosOn where whosOn.workstationName ='" & CurrentComputername & "'"")
rstwhosOn.MoveFirst
Do Until rstwhosOn.EOF
rstwhosOn.Delete
rstwhosOn.MoveNext
Loop
set rstwhosOn = nothing
Set rstwhosOn = dbs.OpenRecordset("whosOn")
rstwhosOn.AddNew
rstwhosOn!workstationName = CurrentComputername
rstwhosOn!UserName = "Logged off"
rstwhosOn.Update
rstwhosOn.Close
dbs.Close
End Sub
Hope this can help ya...
-
Mar 19th, 2000, 01:28 AM
#3
Thread Starter
Lively Member
Variable not being remembered
I've worked out what's wrong now,
in Private sub form_load it gets and sets the currentcomputername variable but by the time we get to sub form_unload, it's forgotten it 
How can I make my app remember it from one form to another?
Thanks all
Simon
-
Mar 20th, 2000, 05:47 PM
#4
Hyperactive Member
Try Global (Public) Declaration of Variable
Hey Simon,
Add a module to your project and add the following line of code:
Code:
Global CurrentComputername as String
By adding a module and declaring the variable Global (Public in VB6, I think), it allows your program to use whatever is saved in your variable anywhere in your project.
Hope that helps.
Let us know,
JazzBass
JazzBass
In the .NET era
Trying to remember VB6
Progress: 
XP Professional @ Home
and @ the Office
-
Mar 20th, 2000, 09:37 PM
#5
Thread Starter
Lively Member
Thanks Jazz! I'll try it out tonight 
Simon
Hey Simon,
Add a module to your project and add the following line of code:
Code:
Global CurrentComputername as String
By adding a module and declaring the variable Global (Public in VB6, I think), it allows your program to use whatever is saved in your variable anywhere in your project.
Hope that helps.
Let us know,
JazzBass
-
Mar 20th, 2000, 10:24 PM
#6
Hyperactive Member
Sure Thing
Your welcome 
Hope that solves your problem.
JazzBass
-
Mar 21st, 2000, 02:19 AM
#7
Thread Starter
Lively Member
Thanks Jazz,
That worked great!
Simon
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|