Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report source problem

Status
Not open for further replies.

martinot

Technical User
Dec 12, 2003
9
BE
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 = &quot;SELECT EmailName, OrganisationID, FirstName, LastName, EmailName, Title, Workphone, FaxNumber FROM Contacts Where Contacts!ContactID <> 0 &quot;

If Not Me.chkAuteur Then
SQL = SQL & &quot;And Contacts!EmailName like '*&quot; & Me.txtRechAuteur & &quot;*' &quot;
End If
If Not Me.chkFamille Then
SQL = SQL & &quot;And Contacts!FirstName like '*&quot; & Me.cmbRechFamille & &quot;*' &quot;
End If
If Not Me.chkResume Then
SQL = SQL & &quot;And Contacts!OrganisationID like '*&quot; & Me.txtRechResume & &quot;*' &quot;
End If
If Not Me.chkTitre Then
SQL = SQL & &quot;And Contacts!Title like '*&quot; & Me.txtRechTitre & &quot;*' &quot;
End If
If Not Me.chkType Then
SQL = SQL & &quot;And Contacts!LastName like '*&quot; & Me.cmbRechType & &quot;*' &quot;
End If

SQLWhere = Trim(Right(SQL, Len(SQL) - InStr(SQL, &quot;Where &quot;) - Len(&quot;Where &quot;) + 1))

SQL = SQL & &quot;;&quot;

Me.lblStats.Caption = DCount(&quot;*&quot;, &quot;Contacts&quot;, SQLWhere) & &quot; / &quot; & DCount(&quot;*&quot;, &quot;Contacts&quot;)
Me.lstResults.RowSource = SQL
Me.lstResults.Requery

End Sub

I then created a button with the onclick;

DoCmd.OpenReport &quot;Contacts&quot;, acViewNormal, , &quot;[OrganisationID] = &quot; & Me.lstResults

But then I don’t know what to do next

Thx in advance for your help

Martinot
 
I would try:
DoCmd.OpenReport &quot;Contacts&quot;, acViewNormal, , SQLWhere

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top