Hello!
I am trying to use a search button to find : 1) VendorName and/or 2)InvoiceNo. One is working while the other is not. When I look for an invoice number, it works but when I try to find a vendor, it does not. The combo box does not list the vendor names as it should. And when I try to type a vendor name I get error message that reads: "The text you entered isn't an item in the list..."
What am I doing wrong? Can anyone please help? Thanks.
The main form is called frmFIND and the subform is called sfrmFindAP which is based on a query. The name of the query is qryAP which is working just fine.
frmFIND has this unbound combo box called cboVendor
Row Source: cboVendor
cmdFIND
And here is my code:
I am trying to use a search button to find : 1) VendorName and/or 2)InvoiceNo. One is working while the other is not. When I look for an invoice number, it works but when I try to find a vendor, it does not. The combo box does not list the vendor names as it should. And when I try to type a vendor name I get error message that reads: "The text you entered isn't an item in the list..."
What am I doing wrong? Can anyone please help? Thanks.
The main form is called frmFIND and the subform is called sfrmFindAP which is based on a query. The name of the query is qryAP which is working just fine.
frmFIND has this unbound combo box called cboVendor
Row Source: cboVendor
Code:
SELECT 0 as VendorID, "<ALL>" as VendorName FROM tblzNull UNION ALL SELECT tblVendors.VendorID, tblVendors.VendorName FROM tblVendors;
Code:
[B]Private Sub cmdFIND_Click()[/B] ' Update the record source Me.sfrmFindAP.Form.RecordSource = "SELECT * FROM qryAP " & BuildFilter ' Requery the subform Me.sfrmFindAP.Requery End Sub
Code:
Private Function BuildFilter() As Variant Dim varWhere As Variant Dim varItem As Variant Dim intIndex As Integer varWhere = Null ' Main filter ' Check for LIKE InvoiceNo If Me.txtInv > "" Then varWhere = varWhere & "[InvoiceNo] LIKE ""*" & Me.txtInv & "*"" AND " End If ' Check for VendorName If Me.cboVendor > 0 Then varWhere = varWhere & "[VendorName] = '" & Me.cboVendor.Column(1) & "' AND " End If ' Check if there is a filter to return... If IsNull(varWhere) Then varWhere = "" Else varWhere = "WHERE " & varWhere ' strip off last "AND" in the filter If Right(varWhere, 5) = " AND " Then varWhere = Left(varWhere, Len(varWhere) - 5) End If End If BuildFilter = varWhere End Function
Comment