5
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?

SteveC
  • 15,808
  • 23
  • 102
  • 173
StuckAtWork
  • 1,613
  • 7
  • 23
  • 37
  • what kind of field is Bathroom in your table? – bart s May 16 '12 at 19:42
  • It's a Lookup Field (I know they're not great to use, but this really will be a strictly Access DB so I didn't see the harm) containing the Numeric auto-number of tblBathrooms.ID. I actually got this figured out though... Type out this question and wait 4 minutes, it clicked. Will provide answer. – StuckAtWork May 16 '12 at 19:51
  • 1
    Okay this forum lack-of-reputation stuff is getting on my nerves now.. just wanted to show the answer as an answer.. 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). If someone else could please write that in an answer, easy 15. – StuckAtWork May 16 '12 at 19:56
  • There's nothing wrong with lookup fields in my opinion. When you open the form and no record is present, you can simply use the form to start a new record (access will create it for you), unless your form is not bound to any recordsource – bart s May 16 '12 at 20:11

3 Answers3

3

Had the same problem, but it had nought to do with VBA syntax. I attempted to set a control (ordernumber) on a form. This ordernumber had to be calculated, which i proceeded to do in VBA. After calculation I would try to set the control (ordernumber) on the form. And that triggered an 2448 error at runtime. Subsequently I discovered that in form design, i had set the control source to a calculation already. So run-time VBA would not allow me to set the control as well. After removal of the calculation in the Control Source of the control in the form design --> Property Sheet window it worked fine. I admit, really stupid mistake, but there you have it. Hope this helps --X--

Xander
  • 31
  • 1
2

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

SeanC
  • 15,695
  • 5
  • 45
  • 66
0

The main form has to be editable in order to change the drop down list, even in the form header area. (VBA was making it non-editable upon loading.)

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Chrispy
  • 1
  • 1