Is there an Intro/Tutorial for Macro/Code Writing for Forms

Creating and using forms
Post Reply
CTBarbarin
Posts: 21
Joined: Thu Apr 02, 2015 6:24 am
Location: Phoenix, AZ

Is there an Intro/Tutorial for Macro/Code Writing for Forms

Post by CTBarbarin »

Hello all,

Is there an intro tutorial for writing code for forms? I've never done it before & I'm winging it based on my knowledge of MS AC/XL VBA and the gridtable.odb example I downloaded from Forum.openoffice.org > Board index > Getting started > Tutorials > Base > Database Examples > [Example] Searching in a form with macros

If anyone wants to help in this thread, here are the details:
  • DB Name: ProdDB.odb
  • Form Name: frmTrips
  • 3 Numeric Field controls on the form:
    • nbrStartMileage
    • nbrEndMileage
    • nbrCalculatedDistance
  • Trying to write code to calculate the difference between nbrStartMileage and nbrEndMileage, then populate nbrCalculatedDistance with that difference. Trying to get this calculation/population to take place when nbrEndMileage loses focus.
  • Created a module in ProdDB.odb > Standard named modFrmTrips
  • Created a procedure in Standard.modFrmTrips named nbrEndMiles_LoseFocus. Wrote the following code in this procedure:

    Code: Select all

    Sub nbrEndMiles_LoseFocus(pobjEvent as object)
    	dim pobjForm as object
    	dim pintStartMiles as integer
    	dim pintEndMiles as integer
    	dim pintDrivenMiles as integer
    	
    	pobjForm=pobjEvent.Source.Parent
    	pintEndMiles = pobjForm.nbrEndMileage
    	pintStartMiles=pobjform.nbrStartMileage
    	pintDrivenMiles = pintEndMiles-pintStartMiles
    	pobjform.nbrCalculatedDistance.Value = pintDrivenMiles
    
    End Sub
    
  • In frmTrips form > nbrEndMileage Numeric Field control > When losing focus event, I linked to the procedure above
When I tab into nbrStartMileage, enter miles, tab into nbrEndMileage, enter miles, then tab out of nbrEndMileage; I get the following error:
Image

Thank you for any help anyone can provide,

CTB

OpenOffice 4.1.2 on Windows 8.1
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Is there an Intro/Tutorial for Macro/Code Writing for Fo

Post by Villeroy »

Use MRI: viewtopic.php?f=74&t=49294 together with the online API reference and developer guide. For script languages (Python, JavaScript and the dreaded Basic dialect) you don't need any SDK but MRI should be installed.
Andrew Pitonyak has done a lot of pioneer work: http://www.pitonyak.org/database/

Personally, I try to avoid all macro code even though (or because) I know quite a bit about the subject.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply