Saving a Record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Brockhouse
    New Member
    • Feb 2007
    • 1

    #1

    Saving a Record

    I have a Visual Basic program that is attached to a 97 access database. I have 6 buttons where users make themselves available and a caption pops up and states that "your name" has been made available. It also calls into play NOW which give the time on the keyboard/machine. How can i save this information with the time and name of the person into either a database or into a text file. Here is the code for one if the buttons.

    Code:
    [Private Sub cmdScharlette_Click()
    
    
        On Error GoTo Errortrap
       frmAssign.datAvail.Recordset.MoveFirst
        frmAssign.datAvail.Recordset.MoveNext 'Move to the 2nd record(Scharlette's)
        If frmAssign.txtAvail.Text = 1 Then
            frmAssign.txtAvail.Text = 0
            lblStatus.Caption = " " & Now & "- Scharlette has been made Unavailable."
       ElseIf frmAssign.txtAvail.Text = 0 Then
            frmAssign.txtAvail.Text = 1
            lblStatus.Caption = " " & Now & "- Scharlette has been made Available."
        End If
        frmAssign.datAvail.Recordset.MoveFirst
        RefreshAvail
        Exit Sub
        
    Errortrap:
        wait (50)
    Return]
    Last edited by Killer42; Feb 21 '07, 12:03 AM. Reason: Please use CODE tags around your code
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Could you perhaps add a couple of fields to your existing table, to hold the status (available or not) and the date/time? For example (keeping in mind I'm somewhat rusty on this stuff, and never have used the data control a great deal)...
    Code:
    Private Sub cmdScharlette_Click()
    
      On Error GoTo Errortrap
      frmAssign.datAvail.Recordset.MoveFirst
      frmAssign.datAvail.Recordset.MoveNext ' Move to the 2nd record (Scharlette's)
      If frmAssign.txtAvail.Text = 1 Then
        frmAssign.txtAvail.Text = 0
        lblStatus.Caption = " " & Now & "- Scharlette has been made Unavailable."
        [B]frmAssign.datAvail.Recordset.Edit
        frmAssign.datAvail.Recordset("Available") = [U]False[/U]
        frmAssign.datAvail.Recordset("When") = Now
        frmAssign.datAvail.Recordset.Update[/B]
      ElseIf frmAssign.txtAvail.Text = 0 Then
        frmAssign.txtAvail.Text = 1
        lblStatus.Caption = " " & Now & "- Scharlette has been made Available."
        [B]frmAssign.datAvail.Recordset.Edit
        frmAssign.datAvail.Recordset("Available") = [U]True[/U]
        frmAssign.datAvail.Recordset("When") = Now
        frmAssign.datAvail.Recordset.Update[/B]
      End If
      frmAssign.datAvail.Recordset.MoveFirst
      RefreshAvail
      Exit Sub
        
    Errortrap:
      wait (50)
      [B]Resume[/B] ' Not Return
    Note, I'm working under the assumption that you're using VB6.

    Comment

    Working...