Results 1 to 7 of 7

Thread: Database access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    Post

    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

  2. #2
    Addicted Member curlywink's Avatar
    Join Date
    Mar 2000
    Location
    Manila, Philippines
    Posts
    141

    Post

    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...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    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

  4. #4
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    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

  6. #6
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Sure Thing

    Your welcome
    Hope that solves your problem.
    JazzBass

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    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
  •  



Click Here to Expand Forum to Full Width