Modify the VBA code to make sure the form is open.
DoCmd.OpenForm "NameOfForm"
This should prevent error # 2450.
Subsequently, you do not need to save the [NameOfTextbox] value in a variable, and then use this variable to create your SQL statement. You can use its value directly.
sqlquery = "SELECT * FROM YourTable " & _ "WHERE some_field = '" & Forms![NameOfForm]![NameOfTextbox] & "';"
Or insert a link to the text field (instead of the value of the text field) in the request.
sqlquery = "SELECT * FROM YourTable " & _ "WHERE some_field = Forms![NameOfForm]![NameOfTextbox];"
I assumed that some_field is a text data type field, so I enclosed the value of the text field with single quotes in the first query example. Note that the second example does not need quotation marks, because it refers to a text field by name, not its value.
However, if you continue your original approach (keeping the value of the text field for the variable), do not call the variable "value", because the value can be confused with the property of many objects.
Hansup
source share