[Solved] Need help with macros in forms

Creating a macro - Writing a Script - Using the API

[Solved] Need help with macros in forms

Postby NiksaVel » Mon Feb 04, 2008 9:30 am

Hi all,

I'm fairly new to OOo, and I have NO experience with writing macros, but I've been reading about it a lot lately...


I was wondering if anyone could help me with the following:

1. I want to be able to generate a report by clicking a button in a form, and the report should show only the SINGLE record that was just entered in that form.


2. I want to be able to start the database directly into the selected form... so that the end user would be unable to mess around with anything exept entering/viewing data in the predefined forms, and than use the function described in #1
regarding this issue, I managed to get the following so far... it opens up the database, but I don't want it to open in project manager view, I want forms, and preferably ONLY the single form, so that the end user doesn't mess around with the database...

Code: Select all   Expand viewCollapse view
Sub LoadMacroDocFromHttp   Dim noArgs()          'An empty array for the arguments.
  Dim vComp             'The loaded component
  Dim sURL As String    'URL of the document to load
  sURL = "file:///home/niksavel/oobaze/rtg/rtg8.odb"
  vComp = StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, noArgs())
End Sub



thanks a lot for all the help!
Last edited by NiksaVel on Mon May 12, 2008 9:39 am, edited 1 time in total.
OOo 3.1.X on Ubuntu 8.x + Linux Mint 7, Win XP, Vista
User avatar
NiksaVel
 
Posts: 91
Joined: Fri Jan 25, 2008 12:00 pm
Location: Croatia

Re: Need help with macros in forms

Postby pitonyak » Tue Feb 19, 2008 1:24 am

I see that there have been no attempts at this... I will make some guesses, that may not be correct.

If you open the database context (rather than the database itself), can you then load the form from the database context? I could check this, but I need to go to sleep (wife's orders)...



Andrew Pitonyak
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
pitonyak
Volunteer
 
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: Need help with macros in forms

Postby QuazzieEvil » Tue Feb 19, 2008 4:55 am

one option is to save your forms as exernal wrriter documents. create the form in Base as usual, when you are all done select 'Save As..' and save to file system. you will have to open the form docs and select a data source as the link is broken when you save it exernally.

another option is to create one form with buttons that opens the forms in the database

Code: Select all   Expand viewCollapse view
Sub OpenForm(FormName As String,DBName As String)
Dim Context As Object
Dim DB As Object
Dim Conn As Object
Dim FormDoc As Object
Dim Form AS Object
Dim Args(1) As New com.sun.star.beans.PropertyValue

Context=CreateUnoService("com.sun.star.sdb.DatabaseContext")
DB=Context.getByName(DBName)
Conn=DB.getConnection("","")

Args(0).Name="ActiveConnection"
Args(0).Value=Conn
Args(1).Name="OpenMode"
Args(1).Value="open”
FormDoc=DB.DatabaseDocument.FormDocuments.loadComponentFromURL (FormName,"_blank",0,Args() )


this code will open a form a form in the diven database.
Code: Select all   Expand viewCollapse view
openForm("EmployeesForm","EmployeesDatabase")


now you can call it from your main/switchboard form. you can have a button & event handler for every form you need to open
Code: Select all   Expand viewCollapse view
Sub cmdOpenForm1_OnClick(Event As Object)
   REM EVENT HANDLER FOR BUTTON cmdOpenForm1
   OpenForm('Form1","TheDB")
End Sub
Sub cmdOpenForm2_OnClick(Event As Object)
   REM EVENT HANDLER FOR BUTTON cmdOpenForm2
   OpenForm('Form2","TheDB")
End Sub
REM AND SO FORTH



as far as your first issue/point, I believe there is a solution in this forum, but I did not find it just now, will have to do a more thorough search.

the idea is to create the report based on a query. you can then change the query (filter) based on the current form filter OR create a filter for the query based on the current record selection.

another options is to create a dummy table and create your report based on this table. from the form (a button on the form), clear the contents of the dummy table, insert the contents of the form's current record into the table, and open the report which is based on this table. you can see my docs at http://www.geocites.com/rbenitez22 for help on working w/ Base & Basic

you can open a report in the same way as the form. the only differnece is that you use the ReportDocuments property of the DatabaseDocument rather than FormDocuments.

--hope this helps. will try to search for the query solution later on-.
QuazzieEvil
Volunteer
 
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Need help with macros in forms

Postby NiksaVel » Wed Feb 20, 2008 7:15 am

Hi,

yeah, I got an in depth explanation regarding report opening from drewjensen, it was really helpful and the solution works 100% :)
viewtopic.php?f=39&t=2391


I also learned already how to open the forms from a button... this is also the part where I have an issue... posted here:
viewtopic.php?p=11302#p11302

I'd like the forms from the button to open in the same window if possible...


and thanks for the reply! :mrgreen:
OOo 3.1.X on Ubuntu 8.x + Linux Mint 7, Win XP, Vista
User avatar
NiksaVel
 
Posts: 91
Joined: Fri Jan 25, 2008 12:00 pm
Location: Croatia


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 1 guest