Multiple Edits

waq963

Registered User.
Local time
Today, 04:32
Joined
Jan 27, 2009
Messages
84
Hi, Basically i have an unbound form which is populated using recordsets. When I i want to edit i use the first save button which works fine on its own. But i would like to make multiple edits. In the combo box i have StudentID, Name. All i need 2 edit is the Score for a student. I Hope this is clear. Thanks

Code:
Private Sub cmdSave_Click()
    If isBlank(txtScore.Value) Then
    MsgBox "Please enter a Score", vbExclamation, "Cannot Save"
        Else
        rstEditQ.Edit
        rstEditQ("Score") = txtScore.Value
        rstEditQ.Update
        Call cmdSave2_Click
    End If
End Sub
Private Sub cmdSave2_Click()
   Dim rstEditprod As DAO.Recordset
    
    Set rstEditprod = dbase.OpenRecordset("tblAQ", dbOpenDynaset)
    If Not IsNull(cboProd1.Value) Then
        rstEditprod.Edit
        rstEditprod("Score") = txtScore.Value
        rstEditprod.Update
    If IsNull(cboProd1.Value) Then
        rstEditprod.Edit
        rstEditprod.CancelUpdate
        rstEditprod.Close
    End If
    End If
End Sub
 
Does you code actually work syntactically as I have never come accross isBlank before?


also you do not need the .Value syntax

Also your cmdsave sub is opening a recordset in it entireity and updating the first record only. That's if there is any records returned, you have not checked for this.
 
isBlank is just an old function i made in a module, just ignore that. The cmdSave works fine it edits the correct data. The cmdSave2 doesn't edit anything. I used the same coding to add multiple records and that works. But i know edits are slightly different and need i just need some sort of direction if possible.
 
In that case use the OnKeyPress event to set a boolean flag that something has changed in the score field. Then on the Exit or Lostfocus of the score field use you save changes script or use DoCmd.RunSQL to update the record. That way the user does not need to click a button to update the value it is done automatically.
 
Cheers, I will give that a go. If there are any examples you could point me towards that would be greatly appreciated.
 
In the forms main declarations section define a boolean variable

Code:
Option Explicit
Dim bFlag As Boolean

Then on the Change event of the control

Code:
Private Sub Score_Change()
'As soon as something changes in the field it sets the variable to true
bFlag = True
End Sub

Code:
Private Sub Score_LostFocus()

If bFlag = True Then
   DoCmd.SetWarnings False
   DoCmd.RunSQL "Update YourTable Set Yourfield = " Me.Score & " Where Your PK = " & PK
   DoCmd.SetWarnings True
   'Reset the flag to false
   bFlag = False
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom