There are two useful commands that you can include in a macro -
Object.dbg_properties
Object.dbg_methods
So for a Form oForm using
oForm.dbg_properties
you will get in a mesage box -
Properties of object
"com.sun.star.comp.forms.ODatabaseForm":
SbxSTRING ActiveCommand; SbxOBJECT/void ActiveConnection; SbxBOOL AllowDeletes;
SbxBOOL AllowInserts; SbxBOOL AllowUpdates; SbxBOOL ApplyFilter;
SbxBOOL CanUpdateInsertedRows; SbxSTRING Command; SbxLONG CommandType;
SbxLONG/void ControlBorderColorOnFocus; SbxLONG/void ControlBorderColorOnHover; SbxLONG/void ControlBorderColorOnInvalid;
SbxLONG/void Cycle; SbxSTRING DataSourceName; SbxARRAY DetailFields;
SbxBOOL/void DynamicControlBorder; SbxBOOL EscapeProcessing; SbxLONG FetchDirection;
SbxLONG FetchSize; SbxSTRING Filter; SbxSTRING GroupBy;
SbxSTRING HavingClause; SbxBOOL IgnoreResult; SbxBOOL IsBookmarkable;
SbxBOOL IsModified; SbxBOOL IsNew; SbxBOOL IsRowCountFinal;
SbxARRAY MasterFields; SbxLONG MaxFieldSize; SbxLONG MaxRows;
SbxSTRING Name; SbxLONG NavigationBarMode; SbxSTRING Order;
SbxSTRING Password; SbxLONG Privileges; SbxBOOL PropertyChangeNotificationEnabled;
SbxLONG QueryTimeOut; SbxLONG ResultSetConcurrency; SbxLONG ResultSetType;
SbxLONG RowCount; SbxOBJECT SingleSelectQueryComposer; SbxLONG SubmitEncoding;
SbxLONG SubmitMethod; SbxSTRING TargetFrame; SbxSTRING TargetURL;
SbxLONG TransactionIsolation; SbxOBJECT/void TypeMap; SbxSTRING URL;
SbxSTRING UpdateCatalogName; SbxSTRING UpdateSchemaName; SbxSTRING UpdateTableName;
SbxSTRING User; SbxOBJECT PropertySetInfo; SbxOBJECT Parameters;
SbxEMPTY Warnings; SbxARRAY Types; SbxARRAY ImplementationId;
SbxOBJECT Delegator; SbxEMPTY Bookmark; SbxOBJECT MetaData;
SbxOBJECT Columns; SbxSTRING ImplementationName; SbxARRAY SupportedServiceNames;
SbxLONG Row; SbxOBJECT Statement; SbxSTRING PropertyToDefault;
SbxOBJECT Parent; SbxBOOL GroupControl; SbxARRAY ControlModels;
SbxLONG GroupCount; SbxOBJECT ElementType; SbxARRAY ElementNames;
SbxLONG Count; SbxSTRING ServiceName; SbxARRAY PropertyValues;
SbxSTRING Dbg_SupportedInterfaces; SbxSTRING Dbg_Properties; SbxSTRING Dbg_Methods
and the methods -
Methods of object
"com.sun.star.comp.forms.ODatabaseForm":
SbxEMPTY queryInterface ( SbxOBJECT ) ; SbxOBJECT getPropertySetInfo ( void ) ; SbxVOID setPropertyValue ( SbxSTRING, SbxVARIANT ) ; SbxEMPTY getPropertyValue ( SbxSTRING ) ; SbxVOID addPropertyChangeListener ( SbxSTRING, SbxOBJECT ) ; SbxVOID removePropertyChangeListener ( SbxSTRING, SbxOBJECT ) ; SbxVOID addVetoableChangeListener ( SbxSTRING, SbxOBJECT ) ; SbxVOID removeVetoableChangeListener ( SbxSTRING, SbxOBJECT ) ;
SbxVOID setFastPropertyValue ( SbxLONG, SbxVARIANT ) ; SbxEMPTY getFastPropertyValue ( SbxLONG ) ; SbxOBJECT getPropertySetInfo ( void ) ; SbxVOID setPropertyValues ( SbxARRAY, SbxARRAY ) ; SbxARRAY getPropertyValues ( SbxARRAY ) ; SbxVOID addPropertiesChangeListener ( SbxARRAY, SbxOBJECT ) ; SbxVOID removePropertiesChangeListener ( SbxOBJECT ) ; SbxVOID firePropertiesChangeEvent ( SbxARRAY, SbxOBJECT ) ;
SbxOBJECT createResultSet ( void ) ; SbxVOID addRowSetApproveListener ( SbxOBJECT ) ; SbxVOID removeRowSetApproveListener ( SbxOBJECT ) ; SbxVOID addRowsChangeListener ( SbxOBJECT ) ; SbxVOID removeRowsChangeListener ( SbxOBJECT ) ; SbxARRAY deleteRows ( SbxARRAY ) ; SbxVOID setNull ( SbxLONG, SbxLONG ) ; SbxVOID setObjectNull ( SbxLONG, SbxLONG, SbxSTRING ) ;
SbxVOID setBoolean ( SbxLONG, SbxBOOL ) ; SbxVOID setByte ( SbxLONG, SbxINTEGER ) ; SbxVOID setShort ( SbxLONG, SbxINTEGER ) ; SbxVOID setInt ( SbxLONG, SbxLONG ) ; SbxVOID setLong ( SbxLONG, SbxINT64 ) ; SbxVOID setFloat ( SbxLONG, SbxSINGLE ) ; SbxVOID setDouble ( SbxLONG, SbxDOUBLE ) ; SbxVOID setString ( SbxLONG, SbxSTRING ) ;
SbxVOID setBytes ( SbxLONG, SbxARRAY ) ; SbxVOID setDate ( SbxLONG, SbxOBJECT ) ; SbxVOID setTime ( SbxLONG, SbxOBJECT ) ; SbxVOID setTimestamp ( SbxLONG, SbxOBJECT ) ; SbxVOID setBinaryStream ( SbxLONG, SbxOBJECT, SbxLONG ) ; SbxVOID setCharacterStream ( SbxLONG, SbxOBJECT, SbxLONG ) ; SbxVOID setObject ( SbxLONG, SbxVARIANT ) ; SbxVOID setObjectWithInfo ( SbxLONG, SbxVARIANT, SbxLONG, SbxLONG ) ;
SbxVOID setRef ( SbxLONG, SbxOBJECT ) ; SbxVOID setBlob ( SbxLONG, SbxOBJECT ) ; SbxVOID setClob ( SbxLONG, SbxOBJECT ) ; SbxVOID setArray ( SbxLONG, SbxOBJECT ) ; SbxVOID clearParameters ( void ) ; SbxVOID disposing ( SbxOBJECT ) ; SbxVOID insertRow ( void ) ; SbxVOID updateRow ( void ) ;
SbxVOID deleteRow ( void ) ; SbxVOID cancelRowUpdates ( void ) ; SbxVOID moveToInsertRow ( void ) ; SbxVOID moveToCurrentRow ( void ) ; SbxVOID updateNull ( SbxLONG ) ; SbxVOID updateBoolean ( SbxLONG, SbxBOOL ) ; SbxVOID updateByte ( SbxLONG, SbxINTEGER ) ; SbxVOID updateShort ( SbxLONG, SbxINTEGER ) ;
SbxVOID updateInt ( SbxLONG, SbxLONG ) ; SbxVOID updateLong ( SbxLONG, SbxINT64 ) ; SbxVOID updateFloat ( SbxLONG, SbxSINGLE ) ; SbxVOID updateDouble ( SbxLONG, SbxDOUBLE ) ; SbxVOID updateString ( SbxLONG, SbxSTRING ) ; SbxVOID updateBytes ( SbxLONG, SbxARRAY ) ; SbxVOID updateDate ( SbxLONG, SbxOBJECT ) ; SbxVOID updateTime ( SbxLONG, SbxOBJECT ) ;
SbxVOID updateTimestamp ( SbxLONG, SbxOBJECT ) ; SbxVOID updateBinaryStream ( SbxLONG, SbxOBJECT, SbxLONG ) ; SbxVOID updateCharacterStream ( SbxLONG, SbxOBJECT, SbxLONG ) ; SbxVOID updateObject ( SbxLONG, SbxVARIANT ) ; SbxVOID updateNumericObject ( SbxLONG, SbxVARIANT, SbxLONG ) ; SbxVOID cancel ( void ) ; SbxVOID executeWithCompletion ( SbxOBJECT ) ; SbxOBJECT getParameters ( void ) ;
SbxEMPTY getWarnings ( void ) ; SbxVOID clearWarnings ( void ) ; SbxARRAY getTypes ( void ) ; SbxARRAY getImplementationId ( void ) ; SbxOBJECT queryAdapter ( void ) ; SbxVOID setDelegator ( SbxOBJECT ) ; SbxEMPTY queryAggregation ( SbxOBJECT ) ; SbxVOID dispose ( void ) ;
SbxVOID addEventListener ( SbxOBJECT ) ; SbxVOID removeEventListener ( SbxOBJECT ) ; SbxEMPTY getBookmark ( void ) ; SbxBOOL moveToBookmark ( SbxVARIANT ) ; SbxBOOL moveRelativeToBookmark ( SbxVARIANT, SbxLONG ) ; SbxLONG compareBookmarks ( SbxVARIANT, SbxVARIANT ) ; SbxBOOL hasOrderedBookmarks ( void ) ; SbxLONG hashBookmark ( SbxVARIANT ) ;
SbxBOOL wasNull ( void ) ; SbxSTRING getString ( SbxLONG ) ; SbxBOOL getBoolean ( SbxLONG ) ; SbxINTEGER getByte ( SbxLONG ) ; SbxINTEGER getShort ( SbxLONG ) ; SbxLONG getInt ( SbxLONG ) ; SbxINT64 getLong ( SbxLONG ) ; SbxSINGLE getFloat ( SbxLONG ) ;
SbxDOUBLE getDouble ( SbxLONG ) ; SbxARRAY getBytes ( SbxLONG ) ; SbxOBJECT getDate ( SbxLONG ) ; SbxOBJECT getTime ( SbxLONG ) ; SbxOBJECT getTimestamp ( SbxLONG ) ; SbxOBJECT getBinaryStream ( SbxLONG ) ; SbxOBJECT getCharacterStream ( SbxLONG ) ; SbxEMPTY getObject ( SbxLONG, SbxOBJECT ) ;
SbxOBJECT getRef ( SbxLONG ) ; SbxOBJECT getBlob ( SbxLONG ) ; SbxOBJECT getClob ( SbxLONG ) ; SbxOBJECT getArray ( SbxLONG ) ; SbxOBJECT getMetaData ( void ) ; SbxLONG findColumn ( SbxSTRING ) ; SbxOBJECT getColumns ( void ) ; SbxSTRING getImplementationName ( void ) ;
SbxBOOL supportsService ( SbxSTRING ) ; SbxARRAY getSupportedServiceNames ( void ) ; SbxBOOL next ( void ) ; SbxBOOL isBeforeFirst ( void ) ; SbxBOOL isAfterLast ( void ) ; SbxBOOL isFirst ( void ) ; SbxBOOL isLast ( void ) ; SbxVOID beforeFirst ( void ) ;
SbxVOID afterLast ( void ) ; SbxBOOL first ( void ) ; SbxBOOL last ( void ) ; SbxLONG getRow ( void ) ; SbxBOOL absolute ( SbxLONG ) ; SbxBOOL relative ( SbxLONG ) ; SbxBOOL previous ( void ) ; SbxVOID refreshRow ( void ) ;
SbxBOOL rowUpdated ( void ) ; SbxBOOL rowInserted ( void ) ; SbxBOOL rowDeleted ( void ) ; SbxOBJECT getStatement ( void ) ; SbxVOID execute ( void ) ; SbxVOID addRowSetListener ( SbxOBJECT ) ; SbxVOID removeRowSetListener ( SbxOBJECT ) ; SbxVOID close ( void ) ;
SbxINT64 getSomething ( SbxARRAY ) ; SbxVOID enableChangeListenerNotification ( SbxBOOL ) ; SbxLONG getPropertyState ( SbxSTRING ) ; SbxARRAY getPropertyStates ( SbxARRAY ) ; SbxVOID setPropertyToDefault ( SbxSTRING ) ; SbxEMPTY getPropertyDefault ( SbxSTRING ) ; SbxOBJECT getParent ( void ) ; SbxVOID setParent ( SbxOBJECT ) ;
SbxBOOL getGroupControl ( void ) ; SbxVOID setGroupControl ( SbxBOOL ) ; SbxVOID setControlModels ( SbxARRAY ) ; SbxARRAY getControlModels ( void ) ; SbxVOID setGroup ( SbxARRAY, SbxSTRING ) ; SbxLONG getGroupCount ( void ) ; SbxVOID getGroup ( SbxLONG, SbxARRAY, SbxSTRING ) ; SbxVOID getGroupByName ( SbxSTRING, SbxARRAY ) ;
SbxVOID loaded ( SbxOBJECT ) ; SbxVOID unloading ( SbxOBJECT ) ; SbxVOID unloaded ( SbxOBJECT ) ; SbxVOID reloading ( SbxOBJECT ) ; SbxVOID reloaded ( SbxOBJECT ) ; SbxVOID cursorMoved ( SbxOBJECT ) ; SbxVOID rowChanged ( SbxOBJECT ) ; SbxVOID rowSetChanged ( SbxOBJECT ) ;
SbxBOOL approveCursorMove ( SbxOBJECT ) ; SbxBOOL approveRowChange ( SbxOBJECT ) ; SbxBOOL approveRowSetChange ( SbxOBJECT ) ; SbxVOID addParameterListener ( SbxOBJECT ) ; SbxVOID removeParameterListener ( SbxOBJECT ) ; SbxVOID addDatabaseParameterListener ( SbxOBJECT ) ; SbxVOID removeDatabaseParameterListener ( SbxOBJECT ) ; SbxVOID errorOccured ( SbxOBJECT ) ;
SbxVOID addSQLErrorListener ( SbxOBJECT ) ; SbxVOID removeSQLErrorListener ( SbxOBJECT ) ; SbxVOID reset ( void ) ; SbxVOID addResetListener ( SbxOBJECT ) ; SbxVOID removeResetListener ( SbxOBJECT ) ; SbxVOID submit ( SbxOBJECT, SbxOBJECT ) ; SbxVOID addSubmitListener ( SbxOBJECT ) ; SbxVOID removeSubmitListener ( SbxOBJECT ) ;
SbxVOID load ( void ) ; SbxVOID unload ( void ) ; SbxVOID reload ( void ) ; SbxBOOL isLoaded ( void ) ; SbxVOID addLoadListener ( SbxOBJECT ) ; SbxVOID removeLoadListener ( SbxOBJECT ) ; SbxSTRING getName ( void ) ; SbxVOID setName ( SbxSTRING ) ;
SbxOBJECT getElementType ( void ) ; SbxBOOL hasElements ( void ) ; SbxEMPTY getByName ( SbxSTRING ) ; SbxARRAY getElementNames ( void ) ; SbxBOOL hasByName ( SbxSTRING ) ; SbxVOID replaceByName ( SbxSTRING, SbxVARIANT ) ; SbxVOID insertByName ( SbxSTRING, SbxVARIANT ) ; SbxVOID removeByName ( SbxSTRING ) ;
SbxLONG getCount ( void ) ; SbxEMPTY getByIndex ( SbxLONG ) ; SbxVOID replaceByIndex ( SbxLONG, SbxVARIANT ) ; SbxVOID insertByIndex ( SbxLONG, SbxVARIANT ) ; SbxVOID removeByIndex ( SbxLONG ) ; SbxVOID addContainerListener ( SbxOBJECT ) ; SbxVOID removeContainerListener ( SbxOBJECT ) ; SbxOBJECT createEnumeration ( void ) ;
SbxVOID registerScriptEvent ( SbxLONG, SbxOBJECT ) ; SbxVOID registerScriptEvents ( SbxLONG, SbxARRAY ) ; SbxVOID revokeScriptEvent ( SbxLONG, SbxSTRING, SbxSTRING, SbxSTRING ) ; SbxVOID revokeScriptEvents ( SbxLONG ) ; SbxVOID insertEntry ( SbxLONG ) ; SbxVOID removeEntry ( SbxLONG ) ; SbxARRAY getScriptEvents ( SbxLONG ) ; SbxVOID attach ( SbxLONG, SbxOBJECT, SbxVARIANT ) ;
SbxVOID detach ( SbxLONG, SbxOBJECT ) ; SbxVOID addScriptListener ( SbxOBJECT ) ; SbxVOID removeScriptListener ( SbxOBJECT ) ; SbxVOID propertyChange ( SbxOBJECT ) ; SbxSTRING getServiceName ( void ) ; SbxVOID write ( SbxOBJECT ) ; SbxVOID read ( SbxOBJECT ) ; SbxOBJECT createClone ( void ) ;
SbxVOID addProperty ( SbxSTRING, SbxINTEGER, SbxVARIANT ) ; SbxVOID removeProperty ( SbxSTRING ) ; SbxARRAY getPropertyValues ( void ) ; SbxVOID setPropertyValues ( SbxARRAY )
You will see that there is a Form method isLast, so you should use oForm.isLast in your IF loop.
Using oForm.last will move the record pointer to the last record.
As @Ratslinger said it appears you are not setting oForm correctly. If the macro is run from a Button on the Form then to get the Form object you need to use -
oForm = oEvent.Source.Model.Parent
The source of the event being the Button and the Form is the parent of the Button.
EDITED 31/10/2016
@Ratslinger Your sample database is a good example of how to use Basic in a LO Base database.
However I disagree with part of your code. You use the Form Event “After record change” to run the Macro “DisplayCurrentRecordChosen” using the even argument oEvent to get the Form Object oForm. You create oField as the source of the event as it is a result of a change in the Grid Control but the change in the Grid Control triggers the FORM event “After record change”. There is no Field creating the event. oField is in fact oForm.
The line -
oForm = oField.Parent.getByName(“MainForm”)
takes the Event source, the Form, gets the parent which is the Forms Collection, and gets the Form “MainForm” by name. In effect going from the Form to the Forms Collection and back to the Form. So oForm can be found by just having -
oForm = oEvent.Source
which works. If using an Event directly created by a control on a Form then oForm can found using -
oForm = oEvent.Source.Model.Parent
@lobito You can run into problems using snippets of code from various sources. Some of the code may only work in a particular context.
It is also worth pointing out that when you use the Event argument oEvent that you can only run the code using the Form. If you attempt to run the code from Macros - Run macro it will fail as there will be no oEvent argument.