BeardedSith
Member
- Local time
- Yesterday, 23:09
- Joined
- Feb 5, 2020
- Messages
- 73
I have a couple procedures I use throughout several of my databases to filter a listbox based on the value in a textbox. I stole these ideas from someone, and honestly can't remember who (so if you're here, thanks and sorry!).
I've tried to determine where the error is coming from, but I'm stumped. I could really use a fresh pair of eyes.
The error exists when I 1) Open the form or 2) Double-Click lstAuctions.
I've been able to trace it down to this line:
Having too few parameters seems like an easy one to figure out, but, like eluded to earlier, this is code that I've used in several projects with perfect results, so I'm not entirely sure where I'm going wrong.
I've tried to determine where the error is coming from, but I'm stumped. I could really use a fresh pair of eyes.
Code:
Option Compare Database
Const LIST_SQL As String = "SELECT ID, ItemList FROM qryAuctionList WHERE ItemList LIKE p0 ORDER BY DateListed"
Private m_qdf As DAO.QueryDef
'''''''''''''''''''''''''''''
Private Sub Form_AfterUpdate()
Call validateSave(Me.Dirty)
End Sub
'''''''''''''''''''''''''''''
Property Get ListQuery() As DAO.QueryDef
If m_qdf Is Nothing Then Set m_qdf = CurrentDb.CreateQueryDef("", LIST_SQL)
Set ListQuery = m_qdf
End Property
'''''''''''''''''''''''''''''
Private Sub FilterList(Optional criteria As String)
criteria = "*" & criteria & "*"
With Me.ListQuery
.Parameters(0) = criteria
Set Me.lstAuctions.Recordset = .OpenRecordset
End With
End Sub
Private Sub cmdClear_Click()
DoCmd.GoToRecord , "", acNewRec
txtFilter.Value = ""
FilterList
End Sub
'''''''''''''''''''''''''''''
Private Sub lstAuctions_DblClick(Cancel As Integer)
DoCmd.SearchForRecord , "", acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))
DoCmd.Requery "lstAuctions"
End Sub
'''''''''''''''''''''''''''''
Private Sub Form_Load()
On Error GoTo Form_Load_Err
FilterList
DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
Form_Load_Exit:
Exit Sub
Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit
End Sub
'''''''''''''''''''''''''''''
Private Sub txtFilter_Change()
FilterList Me.txtFilter.Text
End Sub
The error exists when I 1) Open the form or 2) Double-Click lstAuctions.
I've been able to trace it down to this line:
Code:
Private Sub FilterList(Optional criteria As String)
criteria = "*" & criteria & "*"
With Me.ListQuery
.Parameters(0) = criteria
Set Me.lstAuctions.Recordset = .OpenRecordset 'DEBUG FIRES BACK THE ERORR IS HERE
End With
End Sub
Having too few parameters seems like an easy one to figure out, but, like eluded to earlier, this is code that I've used in several projects with perfect results, so I'm not entirely sure where I'm going wrong.