Hi all,
I’m trying to create a report based on the results of an sql query. The sql query returns a series of result in a listbox called lstresults. What I would like to do is use this listbox as the source for a report . But I don’t know how to proceed ?
My knowledge of access is still very limited so please bear with me. Here is the code I used for the sql query.
Private Sub RefreshQuery()
Dim SQL As String
Dim SQLWhere As String
SQL = "SELECT EmailName, OrganisationID, FirstName, LastName, EmailName, Title, Workphone, FaxNumber FROM Contacts Where Contacts!ContactID <> 0 "
If Not Me.chkAuteur Then
SQL = SQL & "And Contacts!EmailName like '*" & Me.txtRechAuteur & "*' "
End If
If Not Me.chkFamille Then
SQL = SQL & "And Contacts!FirstName like '*" & Me.cmbRechFamille & "*' "
End If
If Not Me.chkResume Then
SQL = SQL & "And Contacts!OrganisationID like '*" & Me.txtRechResume & "*' "
End If
If Not Me.chkTitre Then
SQL = SQL & "And Contacts!Title like '*" & Me.txtRechTitre & "*' "
End If
If Not Me.chkType Then
SQL = SQL & "And Contacts!LastName like '*" & Me.cmbRechType & "*' "
End If
SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where "
- Len("Where "
+ 1))
SQL = SQL & ";"
Me.lblStats.Caption = DCount("*", "Contacts", SQLWhere) & " / " & DCount("*", "Contacts"
Me.lstResults.RowSource = SQL
Me.lstResults.Requery
End Sub
I then created a button with the onclick;
DoCmd.OpenReport "Contacts", acViewNormal, , "[OrganisationID] = " & Me.lstResults
But then I don’t know what to do next
Thx in advance for your help
Martinot
I’m trying to create a report based on the results of an sql query. The sql query returns a series of result in a listbox called lstresults. What I would like to do is use this listbox as the source for a report . But I don’t know how to proceed ?
My knowledge of access is still very limited so please bear with me. Here is the code I used for the sql query.
Private Sub RefreshQuery()
Dim SQL As String
Dim SQLWhere As String
SQL = "SELECT EmailName, OrganisationID, FirstName, LastName, EmailName, Title, Workphone, FaxNumber FROM Contacts Where Contacts!ContactID <> 0 "
If Not Me.chkAuteur Then
SQL = SQL & "And Contacts!EmailName like '*" & Me.txtRechAuteur & "*' "
End If
If Not Me.chkFamille Then
SQL = SQL & "And Contacts!FirstName like '*" & Me.cmbRechFamille & "*' "
End If
If Not Me.chkResume Then
SQL = SQL & "And Contacts!OrganisationID like '*" & Me.txtRechResume & "*' "
End If
If Not Me.chkTitre Then
SQL = SQL & "And Contacts!Title like '*" & Me.txtRechTitre & "*' "
End If
If Not Me.chkType Then
SQL = SQL & "And Contacts!LastName like '*" & Me.cmbRechType & "*' "
End If
SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, "Where "
SQL = SQL & ";"
Me.lblStats.Caption = DCount("*", "Contacts", SQLWhere) & " / " & DCount("*", "Contacts"
Me.lstResults.RowSource = SQL
Me.lstResults.Requery
End Sub
I then created a button with the onclick;
DoCmd.OpenReport "Contacts", acViewNormal, , "[OrganisationID] = " & Me.lstResults
But then I don’t know what to do next
Thx in advance for your help
Martinot