0

Good Morning,

I am trying to use a button's OnClick event on a subform to update a textbox control on the main form each time the button is clicked.

I get the following run-time error:

Run-time error '3075' Syntax error (missing operator) in query expression '[SchoolID]='.

when I run the following code:

Private Sub btnSelect_Click()
Dim schoolName As Variant
schoolName = DLookup("[SchoolTitle]", "Schools", "[SchoolID] = " & [Forms]![frmEnrollment]![frmEnrollmentClassManager]![List11])
Forms!frmEnrollment!txtSchoolName = schoolName
End Sub

Not sure exactly what's going on here. It works fine if I use the DLookup expression as a control source for the textbox control, but when I try and use it with VBA it gives me an error.

Thank you for your time,

-Nick

FunThomas
  • 23,043
  • 3
  • 18
  • 34
  • Why are you saving school name? Should be saving just SchoolID. Include SchoolName as a field in listbox RowSource and won't need DLookup(), just reference listbox column by its index to pull the school name. SchoolID is number type? frmEnrollmentClassManager is name of subform container control? – June7 Feb 02 '22 at 12:19
  • Your object path doesn't look right, check out this: [Forms: Refer to Form and Subform properties and controls](http://access.mvps.org/access/forms/frm0031.htm) – Andre Feb 02 '22 at 15:22

0 Answers0