W
Wendy
I am trying to use a form with a multi select list box to create a query and
then export the data to Excel. Everything works, except the query that is
exported includes all of my data, not just my selections in the list box.
I read in another post that I would need to Save the query, as a new query
with the results and then export. I didn't quite understand the explanation
given.
Here is the code I am using...could use some specific help.
Thank you...Wendy
Private Sub OK_Click()
Dim varItem As Variant
Dim strInClause As String
If Me!lstGLAccount.ItemsSelected.Count = 0 Then
MsgBox ("Please select at least one GL Account.")
Else
strInClause = "[GL_Account] IN ("
For Each varItem In Me!lstGLAccount.ItemsSelected
strInClause = strInClause & """" & Me!lstGLAccount.Column(0,
varItem) & """" & ","
Next varItem
strInClause = Left(strInClause, Len(strInClause) - 1) & ")"
End If
DoCmd.OutputTo acOutputQuery, "qryF2GLSummary_Export", acFormatXLS, , True
DoCmd.Close acForm, "frmGLAccount_Export", acSaveYes
then export the data to Excel. Everything works, except the query that is
exported includes all of my data, not just my selections in the list box.
I read in another post that I would need to Save the query, as a new query
with the results and then export. I didn't quite understand the explanation
given.
Here is the code I am using...could use some specific help.
Thank you...Wendy
Private Sub OK_Click()
Dim varItem As Variant
Dim strInClause As String
If Me!lstGLAccount.ItemsSelected.Count = 0 Then
MsgBox ("Please select at least one GL Account.")
Else
strInClause = "[GL_Account] IN ("
For Each varItem In Me!lstGLAccount.ItemsSelected
strInClause = strInClause & """" & Me!lstGLAccount.Column(0,
varItem) & """" & ","
Next varItem
strInClause = Left(strInClause, Len(strInClause) - 1) & ")"
End If
DoCmd.OutputTo acOutputQuery, "qryF2GLSummary_Export", acFormatXLS, , True
DoCmd.Close acForm, "frmGLAccount_Export", acSaveYes