Hi -
I have a bound form with a bunch of text boxes connected to various fields. When someone types a search value into txtSearch and either tabs out or hits Enter, the following code runs (variable declarations, error handling and clean up omitted):
Things are fine up to where I assign the form's recordsource, at which point Access raises one of those annoying boxes asking for the value of LastName...but I already passed it in via the PARAMETER clause. What is going on here?
As a side note, I recognized that I could assign a SQL string to the recordsource directly, but then I don't know how I would use a parameter. I'm trying to avoid using the text box name directly in the WHERE clause. Thanks.
Pat
I have a bound form with a bunch of text boxes connected to various fields. When someone types a search value into txtSearch and either tabs out or hits Enter, the following code runs (variable declarations, error handling and clean up omitted):
Code:
strGetPersonSQL = "PARAMETERS [LastName] CHAR; " & _ "SELECT tblBasicInfo.*," & _ "tblReferral.*," & _ "tblCountryNames.fldCountry " & _ "FROM tblCountryNames INNER JOIN " & _ "(tblBasicInfo LEFT JOIN " & _ "tblReferral " & _ "ON tblBasicInfo.fldCaseID=tblReferral.fldCaseID) " & _ "ON tblBasicInfo.fldCountryID=tblCountryNames.fldCountryID " & _ "WHERE tblBasicInfo.fldNameLast=[LastName]" Set qdf = CurrentDb.CreateQueryDef("qryGetPersonFromSearch", strGetPersonSQL) qdf("LastName") = Me.txtSearch.Value Set rst = qdf.OpenRecordset(dbOpenSnapshot) If rst.EOF Then MsgBox "Nothing found. Try again...", vbExclamation + vbOKOnly, "Last Name Lookup" rst.Close Set rst=Nothing Exit Sub Else Me.RecordSource = "qryGetPersonFromSearch" End If
As a side note, I recognized that I could assign a SQL string to the recordsource directly, but then I don't know how I would use a parameter. I'm trying to avoid using the text box name directly in the WHERE clause. Thanks.
Pat
Comment