Purdue2479
Registered User.
- Local time
- Today, 16:54
- Joined
- Jul 1, 2003
- Messages
- 52
I am trying to pass a global variable to criteria in a query using the below code, but the query is returning no results. I have the function ReturnStrCriteria() included in the query's criteria. When I manually put the criteria into the query (Like "*2007"), it returns results. Not sure what I'm doing wrong. Any suggestions would be appreciated. Thanks
Module:
Code:
Option Compare Database
Option Explicit
Public Sub cmdOK_Click()
' Declare variables
Dim db As DAO.Database
Dim varItem As Variant
Dim strSQL As String
' Get the database and stored query
Set db = CurrentDb()
DoCmd.RunSQL "Delete * From Table;"
' Loop through the selected items in the list box and build a text string
If Me!lstRebate_Period.ItemsSelected.Count > 0 Then
For Each varItem In Me!lstRebate_Period.ItemsSelected
strCriteria = strCriteria & "Like " & Chr(34) _
& "*" & Me!lstRebate_Period.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "Tbl_Payment_YTD.[Rebate Period] Like '*'"
End If
' Open the query
DoCmd.OpenQuery "Query"
Set db = Nothing
End Sub
Module:
Code:
Option Compare Database
Option Explicit
Public strCriteria As String
Public Function ReturnStrCriteria() As String
ReturnStrCriteria = strCriteria
End Function