Share via

VBA HELP

Anonymous
2014-10-29T21:54:11+00:00

I tried the following codes for adding item not in list:

Private   SUPERVISOR_NotInList(NewData As String, Response As Integer)
If MsgBox("Person not in list, add to List?", vbYesNo,   "Warning") = vbYes Then
DoCmd.OpenForm "FRM_COUNTTEAM", acNormal, , , acFormAdd,   acDialog, NewData
Response = acDataErrAdded
End If
End Sub

In the FRM_COUNTTEAM, I have the following codes in the form property On OPEN event:

Private Sub   Form_Open(Cancel As Integer)
If IsNull(Me.OpenArgs) Then
Else
cmdAddNew_Click
Name = Me.OpenArgs
End If
End Sub

But the error comes out

runtime error  2135 this property is read only and can't   be set<br><br><br>Not sure what causing the error.  Please advise.
Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Anonymous
    2014-10-30T00:47:31+00:00

    Thanks for the information and advice.  I really appreciate this.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-10-29T22:32:27+00:00

    Regardless of the inadvisable use of Name as a column name, your code is a little sparse, and takes no account of the possibility that a user might change their mind and  undo the update of the FRM_COUNTTEAM form.  For examples of the use of the NotInList event procedure in various contexts see NotInList.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

    In this little demo file the NotInList event procedure of the CityID control in the contacts form, and the accompanying code in the cities form's Open event procedure, is the appropriate model for what you are doing.

    However, a more fundamental issue here is that personal names are not distinct, and can legitimately be duplicated.  I worked with two Maggie Taylors.  You might consider this a remote possibility, but even a remote possibility is still a possibility, and a well designed database will take account of this.  The opening form of my demo illustrates an alternative approach by means of a command button.

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2014-10-29T22:19:00+00:00

    "Name" refers to the name of the form running the code (a good reason for not giving a field the name "Name"). Try enclosing Name in square brackets:

            Me.[Name] = Me.OpenArgs

    or

            Me![Name] = Me.OpenArgs

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-10-29T22:08:47+00:00

    I suspect this is a case of using a reserved word. A Form has a read-only Name property; Access assumes you are referring to it, and you're assuming you're referring to a field or control with the name Name.

    If there is a field named Name in the form's recordsource, try changing the fieldname in the table to SupervisorName or some other non-reserved word. You may be able to get away without doing so by explicitly referencing the form control in brackets, so the program doesn't think you're referencing a property:

    Me.[Name] = Me.OpenArgs

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2014-10-29T22:01:26+00:00

    I tried the following codes for adding item not in list:

    Private   SUPERVISOR_NotInList(NewData As String, Response As Integer)
    If MsgBox("Person not in list, add to List?", vbYesNo,   "Warning") = vbYes Then
    DoCmd.OpenForm "FRM_COUNTTEAM", acNormal, , , acFormAdd,   acDialog, NewData
    Response = acDataErrAdded
    End If
    End Sub

    In the FRM_COUNTTEAM, I have the following codes in the form property On OPEN event:

    Private Sub   Form_Open(Cancel As Integer)
    If IsNull(Me.OpenArgs) Then
    Else
    cmdAddNew_Click
    Name = Me.OpenArgs
    End If
    End Sub

    But the error comes out

    runtime error  2135 this property is read only and can't   be set<br><br><br>Not sure what causing the error.  Please advise.

    Further information, debug stop at :

      Name = Me.OpenArgs

    Was this answer helpful?

    0 comments No comments