ms-access

Error 2448: Can't assign a value to this object ... Why not?


Private Sub Form_Open(Cancel As Integer)
  Me.Bathroom = Forms!frmBathrooms!ID
  Me.txtBathInfo.Caption = "Bathroom Room Number: " & 
        DLookup("Room", "tblRooms", "ID = " & 
           DLookup("Room", "tblBathrooms", "ID = " & Me.Bathroom))
  Me.RecordSource = "SELECT * FROM tblStalls WHERE Bathroom = " & Me.Bathroom
  Me.Recordset.AddNew
End Sub

where Line 2 Me.Bathroom = Forms!frmBathrooms!ID is tripping the error. Debugger says Me.Bathroom = 1, Forms!frmBathrooms!ID = 38. Basically I'm trying to automatically make this form's Bathroom field match that of the frmBathrooms form's ID. "Me" is a form for items in the bathroom; there can be many items.

How the hell is that throwing an error? I can't find anything dispite about an hour of searching around. I understand the message, but not how this could be throwing it?

The Bathroom field of the Item table is in the form's recordsource, etc. Ideas?


Solution

  • For anyone else having the same problem, all I did was literally move lines 2 and 3 down to below Me.Recordset.AddNew (so that it changes source and adds a new record BEFORE changing the Me.Bathroom and caption). – user1394455