You did not include the delimiters for the last name, nor did you seperate it out as a variable.
DoCmd.OpenForm stDocName, , , "[LastName] = '" & gLastName & "'"
When writing SQL conditions, strings are surrounded by apostrophes and dates by the pound sign (#). Numbers get nothing. Other Examples:
For a date: DoCmd.OpenForm stDocName, , , "[DateOfBirth] = #" & gDOB & "#"
For a number: DoCmd.OpenForm stDocName, , , "[NoOfDependants] = " & gDependants
For a boolean (yes/no/true/false): DoCmd.OpenForm stDocName, , , "[ActiveRecord] = " & gActive
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|