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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Must execute save twice?

Status
Not open for further replies.

mikelev

Technical User
Mar 23, 2004
223
US
I have a form that is used to set a database backup timer.

Code:
Private Sub Image32_Click()
On Error Resume Next

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblBUDirTime")
    If Not IsNull(Me!txtTime) Or Not Me!txtTime = "" Then
        rs.MoveFirst
        If Not rs.BOF Then
            rs.Edit
        Else
            rs.AddNew
        End If
        rs("TimetoBackUp") = CDate(Me!txtTime)
        rs.Update

       
      
    Else
        MsgBox "You have not selected a back up time to add", vbCritical + vbOKOnly, "StraightEdge Software"
        Me!txtTime.SetFocus
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
        Exit Sub
    End If
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    MsgBox "Backup time saved successfully.", vbInformation, "StraightEdge Software"
    DoCmd.OpenForm "frmtimer"
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblBUDirTime")
    If Not IsNull(Me!txtTime) Or Not Me!txtTime = "" Then
        rs.MoveFirst
        If Not rs.BOF Then
            rs.Edit
        Else
            rs.AddNew
        End If
        rs("TimetoBackUp") = CDate(Me!txtTime)
        rs.Update
      
    Else
        MsgBox "You have not selected a back up time to add", vbCritical + vbOKOnly, "StraightEdge Software"
        Me!txtTime.SetFocus
        rs.Close
        db.Close
        Set rs = Nothing
        Set db = Nothing
        Exit Sub
    End If
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    MsgBox "Remember to Leave open the Backup Timer", vbCritical + vbOKOnly, "StraightEdge Software"
    DoCmd.OpenForm "frmsetup", , , , , acHidden
    DoCmd.OpenForm "FRMTIMER"
    Me.Requery
End Sub


When I execute the Image32_click the form "frmTimer" opens fine, but the table "tblBUDirTime" field "TimetoBackUp" does not update. If I close the form "frmTimer" and execute the Image32_click again the table updates?


Im hoping someone here can see my mistake?

Cheers,
 
How do you know the field TimetoBackUp is not updated? Are you checking the form or the table (via a query)?

If you are verifying the update on the form, use a Requery on the control (text box?).

Richard

 
I am accessing the table by opening the table after the Image32_click is executed.
 
Hmmm.

I assume

I never tried your approach to updating / creating the time. It made me think a bit. I would have approached your coding a tad differently...

Code:
        rs.MoveFirst
        If rs.Count Then
            rs.Edit
            rs("TimetoBackUp") = CDate(Me!txtTime)
            rs.Update
        Else
            rs.AddNew
            rs("TimetoBackUp") = CDate(Me!txtTime)
            rs.Update
        End If

I am not sure if it makes a difference.
 
Just for kicks, I gave it a try and it made no difference.

Appreciate the thought
 
Silly me.........Move the focus after update and you don't have to do it twice!

Thanks all,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top