Question : Setting report recordsource


Hello EE,

   I have a search form that finds machines in the database. At any point the user might want to print a report with the machines found and data about each machine. The sql from the search form needs to become the record source of the report. The report's recordsource is a query called qry_UnitFinderReport. I have the following code:

Private Sub CommandPrintReport_Click()  
    DoCmd.Echo False, ""
    DoCmd.RunCommand acCmdAdvancedFilterSort
    SendKeys "qry_UnitFinderReport{enter}y", False
    DoCmd.RunCommand acCmdSaveAsQuery
    DoCmd.Close , ""
    DoCmd.Echo True, ""
    DoCmd.OpenReport "rptUnitFinder", acPreview, "", ""
End Sub

The problem is that on the computer I made the form and report on, the record source of the report is set up properly with the dialog box to overwrite the old record source being confirmed with the "y" in "SendKeys "qry_UnitFinderReport{enter}y", False"

On other computers where I open the search form and click the report button, a dialog box asking to save the query as "Query1" pops up - instead of saying "qry_UnitFinderReport" and then automatically selecting enter and then "yes". Because of this, the users are confused. Is there anything wrong with the code above? How can this issue be fixed?

Cheers,
Max.

Answer : Setting report recordsource

Max,
Try the code below and let me know............it should be an improvement over what you currently have for these reasons:
        1. Using the SetWarnings False eliminates many of the unnecessary prompts, incuding the prompt at the end, and
        2. reduces the number of keystrokes that need to be sent by SendKeys from 2 to 1 making the SendKeys less risky.
 
____________________________________________________________________________
    Dim stDocName As String
 
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdAdvancedFilterSort
    SendKeys "qry_UnitFinderReport{enter}", False
   
    DoCmd.RunCommand acCmdSaveAsQuery
    DoCmd.Close
    DoCmd.SetWarnings True
   
    stDocName = "rptUnitFinder"
    DoCmd.OpenReport stDocName, acPreview    



Random Solutions  
 
programming4us programming4us