Returning value into Where function

guestbb

Registered User.
Local time
Today, 08:44
Joined
Jul 14, 2015
Messages
44
I have this code that would filter a subform.
My problem is in the bottom of the code where using the WHERE function I filter the record source, but my problem is that it doesnt inser the value of strWhere, but it only leaves the strWhere as a text in the WHERE function and with that not doing anything but causing errors and asking for value of strWhere.
The value of strWhere for example is: ([KatV] Like '*Searched Value*')
And what I want is to replace the strWhere text with this above.
What it is doing now is this: WHERE strWhere
But it should be: WHERE ([KatV] Like '*Searched Value*')
Is there any way to make this happen, to put the value right in the code?


Code:
   Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#dd\/mm\/yyyy\#"
    
    If Not IsNull(Me.cboKatV) Then
        strWhere = strWhere & "([KatV] Like '*" & Me.cboKatV & "*') AND "
    End If

    If Not IsNull(Me.cboMarkaV) Then
        strWhere = strWhere & "([MarkaV] Like '*" & Me.cboMarkaV & "*') AND "
    End If
    
    If Not IsNull(Me.txtModelV) Then
        strWhere = strWhere & "([ModelV] Like '*" & Me.txtModelV & "*') AND "
    End If
    
    If Not IsNull(Me.txtTipM) Then
        strWhere = strWhere & "([TipMotora] Like '*" & Me.txtTipM & "*') AND "
    End If
    
    If Not IsNull(Me.txtRig) Then
        strWhere = strWhere & "([Rig] Like '*" & Me.txtRig & "*') AND "
    End If
    
    If Not IsNull(Me.txtBrSaj) Then
        strWhere = strWhere & "([BrSaj] Like '*" & Me.txtBrSaj & "*') AND "
    End If
    
    If Not IsNull(Me.cboVrGor) Then
        strWhere = strWhere & "([VrGor] Like '*" & Me.cboVrGor & "*') AND "
    End If
    
    If Not IsNull(Me.cboVrstPog) Then
        strWhere = strWhere & "([VrstPog] Like '*" & Me.cboVrstPog & "*') AND "
    End If
    
    If Not IsNull(Me.txtVlaV) Then
        strWhere = strWhere & "([VlaV] Like '*" & Me.txtVlaV & "*') AND "
    End If
    
    If Not IsNull(Me.txtKorV) Then
        strWhere = strWhere & "([KorV] Like '*" & Me.txtKorV & "*') AND "
    End If
    
    If Not IsNull(Me.txtOdDat) Then
        strWhere = strWhere & "([DatV] >= " & Format(Me.txtOdDat, conJetDate) & ") AND "
    End If
    
    If Not IsNull(Me.txtDoDat) Then
        strWhere = strWhere & "([DatV] >= " & Format(Me.txtDoDat, conJetDate) & ") AND "
    End If
    
    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
        Exit Sub
    Else
        strWhere = Left$(strWhere, lngLen)

    SQL = "SELECT qryPV.ID, qryPV.MarkaV, qryPV.ModelV, " _
        & "qryPV.TipM, qryPV.Rig, qryPV.VlaV, " _
        & "qryPV.KorV, qryPV.KatV, qryPV.DatV, " _
        & "qryPV.BrSaj, qryPV.VrstPog, qryPV.VrGor " _
        & "FROM qryPV " _
        & "WHERE [B]strWhere [/B]" _
        & "ORDER BY qryPV.MarkaV "

    Me.subPV.Form.RecordSource = SQL
    Me.subPV.Form.Requery
 
Last edited:
& "WHERE " & strWhere & " " _
 

Users who are viewing this thread

Back
Top Bottom