Edit Record on subform, from input on Form opened by it ?other

liamfitz

Registered User.
Local time
Today, 14:09
Joined
May 17, 2012
Messages
240
The Following code, I hoped would update a field on the subform ( Before_Update event ) which opened it i.e a combo box returned value
Code:
Private Sub cboAssigned_To_Click()
If Me.cboAssigned_To.Text = "" Then
    Response = MsgBox("You have not selected a name", vbInformation, "Referral Assignment")
Else
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim rst As DAO.Recordset
    Set rst = db.OpenRecordset("SELECT tblStaff.Staff_ID From tblStaff WHERE (((tblStaff.CalcStaff_Name)='" & Me.cboAssigned_To.Text & "'));")
    If Not (rst.EOF And rst.BOF) Then
        Dim c As Long
        rst.MoveLast
        c = rst.RecordCount
        If c = 1 Then
            With Forms!frmClients!sfrmReferrals.Form.Recordset
                .Edit
                !Staff_ID = rst.Fields("Staff_ID")
                .Update
            End With
        End If
    End If
    rst.Close
    db.Close
    Set rst = Nothing
    Set db = Nothing
End If
End Sub

As you see, the combo box value should check there is one value associated with it, and if so use that field, to update the opening subform. But I get 'Action cancelled by another object' at the .Edit line. Thanks in advance.
 

Users who are viewing this thread

Back
Top Bottom