Private Sub cmdRunQuery_Click() If Me.lstFieldList.ItemsSelected.Count = 0 Then MsgBox "Select some field names first." Exit Sub End If Dim qDef As Object Dim SQL As String Dim vItem As Variant ' loop through selected field names For Each vItem In Me.lstFieldList.ItemsSelected SQL = SQL & ",[" & Me.lstFieldList.ItemData(vItem) & "]" Next vItem ' build new SQL statement SQL = "Select " & Mid(SQL, 2) & " from [F442audt]" SQL = SQL & " Where [D_Date] Between [Begin Date] and [End Date]" ' save query with new SQL statement Set qDef = CurrentDb.QueryDefs("qryF442audt") qDef.SQL = SQL Set qDef = Nothing ' run query DoCmd.OpenQuery "qryF442audt" End Sub
|I am working on a project management and would like to track the time spent on project task.||10||38|
|Access Open Report with SQL Parameter||11||28|
|Report with several filters - Issue with query?||3||20|
|Trying to force an answer in a combobox||7||10|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
11 Experts available now in Live!