I have a form that I use to add new data to the database. I want to preset certain data values based on other information already entered elsewhere. If I run the following code directly, the values do not show on the screen - if I run it in debug mode line by line, the value of txtAliasFirst does show on the data entry screen:
Sub CEOpen(oEvent as object) ' Open form oContainer = ThisDatabaseDocument.FormDocuments.getByName("CEntry") ocontainer.open Me = oContainer.component.getDrawPage.getforms.getbyindex(0) Me.getByName("txtAliasLast").text = sAliasLName Me.getByName("txtAliasLast").commit() End sub
What command do I need to make the data visible?
I am running into a Function Sequence Error when I try to save the data in the opened form. Here is the situation:
I now have the button on a prior form execute this macro to open form “CEntry” to add a new record:
Sub CEOpen(oEvent as object) ' Open form ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM ThisDataBaseDocument.CurrentController.Connect() ThisDatabaseDocument.CurrentController.loadComponent(ObjTypeWhat,"CEntry", FALSE) End sub
A second macro is tied to the When Loading Event of the form:
Sub CEInit(oEvent as object) Me = ThisComponent.Drawpage.Forms.getByName("fCEntry") ' fCEntry' is the name of the Main_Form Me.getByName("txtClearance Performed By").text = mUser Me.getByName("txtClearance Performed By").commit() ' . . . several other screen fields are loaded from Global variables like mUser End Sub
There is also a button on this screen that reads in values for additional screen fields from a CSV file.
The user has a chance to edit the data brought in from the Global variables, the CSV file, or add additional data entered by hand. All data on the screen appears correct.
The error arises in a Save button macro:
Sub CESave (oEvent as Object) Me = oEvent.Source.Model.Parent oDatasource = ThisDatabaseDocument.CurrentController If NOT (oDatasource.isConnected()) THEN oDatasource.connect() oConnection = oDatasource.ActiveConnection() Me.UpdateRow() End Sub
The Me.UpdateRow() generates the Function Sequence Error. (Me.isModified and Me.isNew are TRUE. I have compared the Me objects in all four macros and it appears to refer to the same oDatabaseForm). In addition, if I close the window manually and say Yes to saving the changes, all the data is saved correctly. What am I missing???