Hello all,
I posted this in a comment on another thread, but have realized the issue is not completely related to the original post, so I thought I'd start a new one.
I'm working on a multi-field search form and I'm using variables for each search field to prevent my lines of code from exponentially multiplying. Here's a relevant snippet of code from the form:
	
	
	
		
This code opens frmAdvancedSearchSelectItem displaying all records in the Items table, not just the ones matching the string in txtItemSearch1. I've played around with a bunch of variations on this code and none of them work. Most other variations give me a "Variable not defined" error. I clearly don't understand the necessary syntax for using a variable for a WHERE condition. Any ideas?
 I posted this in a comment on another thread, but have realized the issue is not completely related to the original post, so I thought I'd start a new one.
I'm working on a multi-field search form and I'm using variables for each search field to prevent my lines of code from exponentially multiplying. Here's a relevant snippet of code from the form:
		Code:
	
	
	Public Sub BuildSQL()
    Dim FieldWhere1 As String
 
    If Me.cboItemField1 = "TITLE" Then
        Set FieldWhere1 = "ItemName Like '*" & [Forms]![frmAdvancedSearch]![txtItemSearch1] & "*' "
            ElseIf Me.cboItemField1 = "YEAR" Then
                  FieldWhere1 = "ItemYearOfProvenance Like '*" & [Forms]![frmAdvancedSearch]![txtItemSearch1] & "*' "
            ElseIf Me.cboItemField1 = "LOCATION" Then
                  FieldWhere1 = "ItemLocation = [Forms]![frmAdvancedSearch]![cboLocationSearch1]"
            ElseIf Me.cboItemField1 = "DESCRIPTION" Then
                  FieldWhere1 = "ItemDescription Like '*" & [Forms]![frmAdvancedSearch]![txtItemSearch1] & "*' "
            ElseIf Me.cboItemField1 = "STATEMENT OF RESPONSIBILITY" Then
                  FieldWhere1 = "ItemStatementOfResponsibility Like '*" & [Forms]![frmAdvancedSearch]![txtItemSearch1] & "*' "
    End If
End Sub
Private Sub cmdItemSearch_Click()
    DoCmd.OpenForm "frmAdvancedSearchSelectItem", acNormal, , "' & FieldWhere1 & '", acFormPropertySettings, acWindowNormal
 
End SubThis code opens frmAdvancedSearchSelectItem displaying all records in the Items table, not just the ones matching the string in txtItemSearch1. I've played around with a bunch of variations on this code and none of them work. Most other variations give me a "Variable not defined" error. I clearly don't understand the necessary syntax for using a variable for a WHERE condition. Any ideas?
 
	 
 
		 
 
		 
 
		