I am an Access novice, but I want to refresh a subform on a main form using a query that looks at a list box and date fields on the main form.
Here are the names/queiries, forms, controls involved:
Table: Opportunity
MainForm: SearchMain
SubFrom: ProposalsSub
Query: Proposals2
Mainform Listbox Control Name: FDisposition
Mainform Date Control Box: RDateS and RDateF
The query proposals2 is the control source for the Form. I have the list Box set up for multiselect. I found some existing code to get me started but could not get it to work.
HTML Code:
Private Sub Command12_Click()
Dim db As DAO.DatabaseDim qdf As DAO.QueryDefDim varItem As VariantDim strCriteria As StringDim strSQL As String
Set db = CurrentDb()Set qdf = db.QueryDefs("Proposals2")'Now for the code that reads the user's selection from the listbox:For Each varItem In Me!FDisposition.ItemsSelected strCriteria = strCriteria & ",'" & Me!FDisposition.ItemData(varItem) & "'"Next varItemstrCriteria = Right(strCriteria, Len(strCriteria) - 1)'The criteria string is now ready to be incorporated into an SQL statement. For this example I have kept the SQL statement simple. You can see how the criteria string variable is added between the brackets of the IN( ---string goes here--- ) expression:strSQL = "SELECT * FROM tblOpportunity " & _ "WHERE tblOpportunity.Disposition IN(" & strCriteria & ");"
DoCmd.OpenQuery "Proposals2"End Sub
Any help would be greatly appreciated.