UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Export Only The Results The Search To Richtext File, Access 2007    
 
   
josephbupe
post Jun 12 2018, 09:26 AM
Post#1



Posts: 814
Joined: 23-January 08
From: Lusaka,Zambia


Greetings,

I have a form with several unbound fields for searching the database with. The searching code is behind a search button

CODE
Private Sub CommandSearch_Click()

' more code here

If Len(strWhere) > 0 Then
    If Nz(DCount("*", "qryEvents", Left(strWhere, Len(strWhere) - 0)), 0) > 0 Then
       strWhere = "WHERE " & Left(strWhere, Len(strWhere) - 0)
       strSQL = "SELECT * FROM qryEvents " & strWhere & ";"
              
        Forms![frmEvents_Search].Form.RecordSource = strSQL
        
        Else
        MsgBox "No records matching your criteria were found.", vbInformation, "Events database"
        End If

    End If
    
End Sub


Now I am trying to export the results of search done with the previous code above to a rich-text file with the following code:

CODE
Private Sub CommandExport_Click()
Dim db As Database
Dim qdf As QueryDef
Dim strSQL As String
Dim rsCriteria As Recordset

Set db = CurrentDb
Set rsCriteria = db.OpenRecordset("qryEvents", dbOpenDynaset)

'*** the first record in the Criteria table ***
rsCriteria.MoveFirst

'*** loop to move through the records in Criteria table
Do Until rsCriteria.EOF

'*** create the Select query based on
' the first record in the Criteria table
strSQL = "SELECT * FROM tblEvents WHERE "
strSQL = strSQL & "[Event_ID] = " & rsCriteria![Event_ID]

'*** delete the previous query
'db.QueryDefs.Delete "qryEvents2"
Set qdf = db.CreateQueryDef("qryEvents2", strSQL)
DoCmd.OutputTo acReport, "rptEvents", "RichTextFormat(*.rtf)", "C:\SARPCCO accdb\SARPCCO_Report.rtf" ', False
rsCriteria.MoveNext
Loop
End Sub


The problem I have is that the export button is exporting all the records from the database to the rich-text file. I want to export only the results of the search.

Hoping to get some help here.

Thanks.



Go to the top of the page
 
zaxbat
post Jun 17 2018, 03:34 AM
Post#2



Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)


The code takes the form data from queryevents table/query but the export does not....the export takes the data from tblevents.

I can only guess that the queryevents is a subset of the tblevents....so it is already filtered and pulled only what you want.....but then you do not export it.....instead you go and export from the whole table tblevents.....

At least, that is what it looks like from a brieft study.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    26th September 2018 - 07:38 AM