TOPIC: How to print from a browse control ?
#137
How to print from a browse control ? 4 Years, 5 Months ago
I think a very nice feature of MS-Access is the possibility to quick print out the records displayed in a query (in a tabular format) by a simple menu command.
In a similar way I would like to have a 'Print' command (for example, in the context menu of a BrowseControl window) that simply prints out all the rows listed in the Browse exactly as they are displayed in the window (I mean with the same columns order).
In this way, the user could change the order of the columns and then he could print out the query in the way he prefers (and this would be a quick and useful way to print some browsed data).
Is there a way to do this?
 
 
Mauro
 
#138
Re:How to print from a browse control ? 4 Years, 5 Months ago
No, there is nothing like that. It is a good idea. Probably wouldn't be hard to do. Currently, you would have to use Reporter, but that would mean re-choosing columns etc.
 
 
andrew
 
#139
Re:How to print from a browse control ? 4 Years, 5 Months ago
The reporter is a good tool but it is more oriented to an experienced Suneido user, while the app I want to develop has to be newbie-proof.
In fact I think I'll remove all the not requested buttons from my access controls.
For now I will switch from browse controls to reports.

P.S.: can I see the code of the reports saved by the reporter tool? In this way, at least I could use it as a base to create my reports.
 
 
Mauro
 
#140
Re:How to print from a browse control ? 4 Years, 5 Months ago
Reporter does not actually generate report code like you would write by hand. You could look at some of the simpler Accounting reports for examples. It is quite easy to generate simple reports - you can just specify the query and the output columns.
 
 
andrew
 
#143
Re:How to print from a browse control ? 4 Years, 4 Months ago
Hi, I have updated the BrowseControl to do what I wanted: a context menu command to print out quickly the record displayed in a BrowseControl without to write code for a report. Just right click in a BrowseControl area and select 'Print...'.
Additionally, if you change the order of the header columns, this will be reflected in the printed records too!

Below the changes to BrowseControl class:

Code:

New(query, columns = false, linkField = false, stickyFields = false,
validField = false, protectField = false, title = false,
statusBar = false, headerFields = #(), dataMember = "browse_data",
noShading = false, noHeaderButtons = false, notifyLast = false,
columnsSaveName = false, buttonBar = false, headerSelectPrompt = false)
{
super(.createControls(title, statusBar, noShading,
noHeaderButtons, buttonBar, headerSelectPrompt));
// observer_ListRow is used as a straight function (not as a Browse method)
// therefore "this" is the record that was modified
// so ._browse is coming from the record
.observer_ListRow = function (member)
{
._browse.Observer_ListRow2(this, member)
}
.Title = query.Tr("rnt", " ") $ " - Browse";
.title = title
.statusBar = statusBar ? .Vert.Status : false;
.original_columns = columns
.headerFields = headerFields;
.columnsSaveName = columnsSaveName
.headerSelectPrompt = headerSelectPrompt
if (.statusBar isnt false) .statusBar.SetValid(true);
.list = .Member?("Vert") ? .Vert.List : .List;
.list.SetMultiSelect(true);
.SetStickyFields(stickyFields);
.SetValidationField(validField);
.SetProtectField(protectField);
.SetLinkField(linkField);
.SetDataMember(dataMember);
.SetQuery(query, columns);
.Send("Data");
if (linkField is false)
.Window.AddValidationItem(this)
if notifyLast is true // use 10 to ensure browse is last notified
.Send("AccessObserver", .AccessChanged, 10)
else
.Send("AccessObserver", .AccessChanged)
.menu = Object("Customize Columns...", "", "Save All", "Restore All", "", "Export...", "Import...")
if linkField is false
.menu = .menu.Add("Print...", "Reporter...", "Summarize...", "CrossTable...", at: 3) //***added Print
}

On_Context_Print() //*** ADDED METHOD FOR 'Print...' NEW CONTEXT MENU COMMAND
{
Params(Object('Query', .query $ ' project ' $ .list.GetColumns().Delete(0).Join(", ")))
// the Delete(0) is to remove the 'listrow_delete' column that is not necessary to the report
}



I would like to print the title of the report and the date too on top of each page (and number of the page on the bottom) that is generated from the On_Context_Print command above, but I'm not yet familiar with reports in Suneido. Maybe someone can help me?
 
 
Mauro
 
#144
Re:How to print from a browse control ? 4 Years, 4 Months ago
Hi Mauro. To get the date, page number, and title to print on your report, all you have to do is pass the title into the Params, like this:

Params(Object('Query', .query $ ' project ' $ .list.GetColumns().Delete(0).Join(", ")), title: "Title")

Although, this will print the page number at the top of the page, not the bottom.

Hope this helps.

Post edited by: jennebelle, at: 2006/03/31 15:01
 
 
#145
Re:How to print from a browse control ? 4 Years, 4 Months ago
Thank you very much jennebelle! :)

Now I use:

Params(Object('Query', .query $ ' project ' $ .list.GetColumns().Delete(0).Join(", ")), title: .title)

In this way, the title is not static but it is taken from the title parameter passed to the BrowseControl. ;)
 
 
Mauro
 
#146
Re:How to print from a browse control ? 4 Years, 4 Months ago
No problem Mauro. Just to let you know, I will be adding your change to the stdlib for the next release. Thanks.
 
 
#147
Re:How to print from a browse control ? 4 Years, 4 Months ago
I'm very happy I could help! :)
 
 
Mauro
 
#148
UPDATE:How to print from a browse control ? 4 Years, 4 Months ago
Hi, there was a problem in my approach. As it can be noticed, I used a 'project' operation to select from the query only the columns displayed in the BrowseControl:

Params(Object('Query', .query $ ' project ' $ .list.GetColumns().Delete(0).Join(", ")), title: .title)

But 'project' removes all the duplicate rows and then, if in the columns there isn't at least a unique field (e.g. a key), it could be displayed a "PROJECT NOT UNIQUE" warning message and the duplicate rows will be printed only once. This isn't the behavior that a user is expected from the print command (it should print all the rows displayed in the list, whether duplicate or not).

Therefore I have modified the QueryFormat class to accept the parameter 'Columns'. In this way I can specify which columns of the query have to be in the report, without to use 'project' and without lose duplicate rows:

In the BrowseControl class:
Code:

On_Context_Print()
{
Params(Object('Query', .query, Columns: .list.GetColumns().Delete(0)), title: (.title isnt false)? .title : '' )
}



You can notice that I have changed the 'title' part too in the above code, because the old code went in error if the title parameter was not specified and the user selected the 'Print...' context menu command.

Finally, below there are the changes in the QueryFormat class:

Code:

New(@args)
{
.Columns = false  //***ADDED
for (m in args.Members())
if (m is 0)
.Query = args[0]
else
this[m.Capitalize()] = args[m]
_report.RegisterForClose(this)
.Params = _report.Params;

query = .Val_or_func('Query');
if (.Member?('InputParams'))
query = QueryAddWhere(query,
_report.GetParamsWhere(@.InputParams));

.t = Transaction(read:)
.q = .t.Query(query);
if "" isnt s = CheckQuery(.q)
Warning(s $ ' ' $ query)

.output = .Val_or_func('Output')
.outputformat = .Val_or_func('OutputFormat')
if (.output is '') {
if (.Columns isnt false) //***ADDED
.output = .outputformat is false ? Object("Row").Add(@.Columns) : false //***ADDED
else //***ADDED
.output = .outputformat is false ? Object("Row").Add(@.q.Columns()) : false
}
if (.output isnt false)
.output = _report.Construct(.output);
...
...
}


The changes are commented by '//***ADDED'.

Post edited by: Mauro, at: 2006/04/01 16:00
 
 
Mauro
 
#149
Re:UPDATE:How to print from a browse control ? 4 Years, 4 Months ago
Hi Mauro.

Instead of changing QueryFormat, you could change your BrowseControl code to be like this:

Code:

On_Context_Print()
    {
    Params(Object(.print_rep, Query: .query, List: .list), 
        title: .title isnt false ? .title : '')
    }
print_rep: QueryFormat
    {
    Query()
        {
        return .Query
        }
    Output()
        {
        ob = Object('Row')
        // the Delete(0) is to remove the 'listrow_delete' column that is not necessary to the report
        for col in .List.GetColumns().Delete(0)
            ob.Add(col)
        return ob
        }
    }



Post edited by: jennebelle, at: 2006/04/03 14:28
 
 
#150
Re:UPDATE:How to print from a browse control ? 4 Years, 4 Months ago
Yes, it is an alternative way, but I prefer my modified QueryFormat, because I think is nice to can select the columns to print in the QueryFormat.
Anyway, why is there this in your code:

Query()
{
return .Query
}

If I comment these rows, it is working too.
 
 
Mauro
 
#151
Re:UPDATE:How to print from a browse control ? 4 Years, 4 Months ago
Hi Mauro. You are right, I did not need the extra Query() method.