| View previous topic :: View next topic |
| Author |
Message |
Zeke99 Newbie

Joined: 30 May 2011 Posts: 4
|
Posted: Mon May 30, 2011 10:57 am Post subject: [Solved] Report from one record in a form |
|
|
Hi
I have a table named customertable with three textfields, Name, Adress, POadress and a keyfield (integer) named ID.
I have a form ,customerform, were I can view one record a time, txtName, txtAdress, txtPOadress and ID.
I have a report, customerreport.odt (made by Oracle report builder) with three fields, Name, Adress and POadress.
Now I want a button in my form to push when I want to print an adresslabel.
Any idea what to put between
sub printadresslabel
...
end sub
in order to print only the fields for the active record just showing in the form.
Last edited by Zeke99 on Wed Jun 01, 2011 11:32 pm; edited 1 time in total |
|
| Back to top |
|
 |
dniezby OOo Enthusiast


Joined: 01 May 2004 Posts: 102
|
Posted: Tue May 31, 2011 6:32 am Post subject: |
|
|
| I'm still learning a lot right now but I would say create a mailmerge document and select the database you've created as it's source. Then you can create all the labels you want even print specific ones. |
|
| Back to top |
|
 |
Zeke99 Newbie

Joined: 30 May 2011 Posts: 4
|
Posted: Tue May 31, 2011 8:18 am Post subject: |
|
|
I have never used a mailmerge document so I'm unfamiliar with that. Can you activate it from a pushbutton inside a form? How do you write the macro for that?
If I use the macro below I print a copy of the current form.
sub printest
Dim aPrintOps(0) As New com.sun.star.beans.PropertyValue
oDoc = ThisComponent
oVCurs = oDoc.CurrentController.getViewCursor()
aPrintOps(0).Name = "Pages"
aPrintOps(0).Value = trim(str(oVCurs.getPage()))
oDoc.print(aPrintOps())
end sub
But I want to be able to use a report from Oracle report builder. Any suggestions? |
|
| Back to top |
|
 |
dniezby OOo Enthusiast


Joined: 01 May 2004 Posts: 102
|
Posted: Tue May 31, 2011 8:55 am Post subject: |
|
|
From what I know, you'd create the document separately.
You could just use the mail merge wizard to create a sample document to practice with.
Then in the form within your database, you'd simply create a push button on your form.
To open the mail merge document, edit the push button control to
Action: Open form/url
Then you will be prompted to select the file you want to open. Select that merged document.
At least that's the way I'd try to go.
No macro writing needed.
You seem excited to jump right into writing macros? Try starting with simple methods first. There usually is a simple method for everything and more efficient. |
|
| Back to top |
|
 |
Zeke99 Newbie

Joined: 30 May 2011 Posts: 4
|
Posted: Tue May 31, 2011 12:51 pm Post subject: |
|
|
I'm replacing a company business system. The company is migrating from Windows to Linux. There are many users, some computer wizards and some on neanderthal level. It's atmost important that everything is selfexplaning, easy to use and foolproof. When you push that button in the form there must be no extra forms or dialog popping up, just the document coming out from the printer.
Getting the keyfield from the form is working
sub getfromtextbox (Event As Object)
Dim Form As Object
Dim KeyTxt As Object
Form=Event.Source.Model.Parent
KeyTxt=Form.GetByName("txtkeyfield")
....
....
End Sub
Opening and printing the report is working.
Sub OpenAdressReport(oEvent As Object)
Dim RptName as string
RptName = "AdressLabel"
ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
End Sub
It's just the method or syntax to get the keyfield filtering the report that missing.
In Access there was an OpenReport-macro where you could put a SQL-expression like [DELKEY]=[Form]![Formname]![DELKEY].
I suppose I could base the report on a Query but I still need to put the KeyField into that SQL-expression without the user doing anything except pushing that button in the form. |
|
| Back to top |
|
 |
Zeke99 Newbie

Joined: 30 May 2011 Posts: 4
|
Posted: Wed Jun 01, 2011 11:29 pm Post subject: |
|
|
Amazing what a good nights sleep can do.
It's not ideal but this solution works for now. The cost is an extra character to every record.
I attach an extra field, FilterPrint, to the table Customertable.
In Oracle Report Builder I set a Filter condition FilterPrint='P'
To the pushbutton in my form I connect the macro below:
REM ***********************************
REM
REM Open a report from a push on
REM a pushbutton in a form
REM
REM The table needs an extra field
REM (FilterPrint) that can be
REM filtered by the report
REM
REM ***********************************
Sub OpenMyReport(Event As Object)
Dim RptName as string
Dim Form As Object
Dim Txt As Object
Dim Column as object
Form=Event.Source.Model.Parent
REM Make the connection to the form
Column=Form.Columns.GetByName("FilterPrint")
Column.updateString("P")
REM Put a P in the FilterPrint textbox
Form.updateRow()
REM Update the table
RptName = "Kundrapport"
REM the name of the report I want to open
ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
REM Open the report
Column=Form.Columns.GetByName("FilterPrint")
Column.updateString("N")
REM Put an N in the FilterPrint textbox
Form.updateRow()
REM Update the table
End Sub |
|
| Back to top |
|
 |
|