Not Recognising Form name ?

liamfitz

Registered User.
Local time
Today, 20:00
Joined
May 17, 2012
Messages
240
The following should reference a subform from another Form. It doesn't recognise the name of the Main form however ( it's definitely correct )

Code:
With Forms!frmAfAIS(test)!frmReferrals.Form.Recordset
                .Edit
                !Staff_ID = rst.Fields("Staff_ID")
                .Update
            End With

As you can see, I'm tring to edit/update a field, that is a part of the recordset of that subform. Any ideas.
 
Are you sure it's the main form that is not being recognized and not the Subform Control? The Subform Control may or may not have the same name as the subform itself, so you should double check the naming of both objects. Having said that, why not just update the underlying table directly with either;

An Update query:

Code:
Dim strUpdate As String

strUpdate = "Update YourTable Set Staff_ID=" & rst!Staff_ID _
          & " Where SomeField = SomeValue;"

CurrentDb.Execute strUpdate, dbFailOnError

Or open a RecordSet to edit:

Code:
Dim strSQL As String

strSQL = "Select * From YourTable Where SomeField = SomeValue;"

With CurrentDb.OpenRecordSet(strSQL)
    If .RecordCount > 0 Then
        .Edit
        !Staff_ID = rst!Staff_ID
        .Update
    End If
End With

The above are untested air code but should give you an idea of different ways to approach it.
 
Is this your actual form name (including the parens)?
Forms!frmAfAIS(test)

If so, then to refer to it you would need to have square brackets (one more reason why not to use spaces or special characters in names):
Forms![frmAfAIS(test)]

Or you can use

Forms("frmAfAIS(test)")
 

Users who are viewing this thread

Back
Top Bottom