Hi, I finally got the snippet creator working, so here are two snippets for the collection.
Marc
<?xml version="1.0"?> <!-- $RCSfile: $ last change: $Revision: $ $Author: $ $Date: $ (c)2003 by the copyright holders listed with the author-tags. If no explicit copyright holder is mentioned with a certain author, the author him-/herself is the copyright holder. All rights reserved. Public Documentation License Notice: The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at http://www.openoffice.org/licenses/PDL.html The Original Documentation can be found in the CVS archives of openoffice.org at the place specified by RCSfile: in this header. The Initial Writer(s) of the Original Documentation are listed with the author-tags below. The Contributor(s) are listed with the author-tags below without the marker for being an initial author. All Rights Reserved. --> <snippet language="OOBasic" application="Database"> <keywords> <keyword>listbox</keyword> <keyword>form</keyword> <keyword>sql</keyword> <keyword>list source</keyword> </keywords> <authors> <author id="ms2" initial="true" email="[EMAIL PROTECTED]">Marc Santhoff</author> </authors> <question heading="change listbox source">How can I change the SQL list source of a ListBox? <p>A query (SQL) based listbox has a fixed SQL statement for it's source.</p> <p>Sometimes it is useful to change this statement by code, e.g. when using one form with different queries.</p> </question> <answer> <listing>Sub changeLBSource ' caution: if you change like this and then save the form ' the SQL statement filled in when designing the form is ' overwritten with the new one, your code should hold both of them! dim oDoc as object, oForm as object dim oListboxModel as object dim ssql(0) as string oDoc = ThisComponent oForm = oDoc.DrawPage.Forms(0) oListboxModel = oForm.getByName("ListBox") ssql(0) = "select ""name"", ""ID"" from ""color""" oListboxModel.ListSource() = ssql() oListboxModel.refresh() End Sub </listing> </answer> <versions> <version number="1.1.x" status="tested"/> <version number="2.2.0" status="tested"/> </versions> <operating-systems> <operating-system name="All"/> </operating-systems> <changelog> <change author-id="ms2" date="2007-09-24">Initial version</change> </changelog> </snippet>
<?xml version="1.0"?> <!-- $RCSfile: $ last change: $Revision: $ $Author: $ $Date: $ (c)2003 by the copyright holders listed with the author-tags. If no explicit copyright holder is mentioned with a certain author, the author him-/herself is the copyright holder. All rights reserved. Public Documentation License Notice: The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at http://www.openoffice.org/licenses/PDL.html The Original Documentation can be found in the CVS archives of openoffice.org at the place specified by RCSfile: in this header. The Initial Writer(s) of the Original Documentation are listed with the author-tags below. The Contributor(s) are listed with the author-tags below without the marker for being an initial author. All Rights Reserved. --> <snippet language="OOBasic" application="Database"> <keywords> <keyword>record</keyword> <keyword>template</keyword> <keyword>form</keyword> <keyword>copy</keyword> </keywords> <authors> <author id="ms2" initial="true" email="[EMAIL PROTECTED]">Marc Santhoff</author> </authors> <question heading="copy record to new">How can I copy an existing record to a new one as template? <p>When typing in data into a database form sometimes many records only differ in a small number of fields.</p> <p>In this case it is desirable to copy one record to a new, empty one and only change the minor differences by hand.</p> </question> <answer> <listing>' Copies the value currently shown in the form ' as a template to a new record. This new record only ' is displayed for editing, not stored yet. ' Only some control types are checked here, please ' add missing types needing special treatment. ' The programmer or user has to take care of adding a ' new primary key into the corresponding field control. ' event binding sub sub copyToNewEvent(evt as object) copyRecordToNewRecord(thisComponent) end sub sub copyRecordToNewRecord(oDoc as object, optional sKeyfieldname as string) dim aVal as Variant dim ccount as integer dim i as integer if IsMissing(sKeyfieldname) then sKeyfieldname = "ID" oForm = oDoc.Drawpage.Forms(0) ccount = oForm.count redim aVal(ccount) ' Step 1 --> get the current fields content (excluding key field for auto values) ' loop over all controls for i=0 to ccount-1 aControl = oForm.getByIndex(i) ' only get controls storing database values if HasUNOInterfaces(aControl, "[EMAIL PROTECTED] com.sun.star.form.XBoundComponent}") then ' read currently shown value n = aControl.name ' exclude primary key field if (InStr(sKeyfieldname, n)=0) then if aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlDateFieldModel}") then aVal(i) = aControl.Date elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlTimeFieldModel}") then aVal(i) = aControl.Time elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlListBoxModel}") then aVal(i) = oDoc.currentController.getControl(aControl).SelectedItemPos elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlFormattedFieldModel}") then aVal(i) = aControl.EffectiveValue else aVal(i) = aControl.Text end if end if end if next i ' Step 2 --> make a new record in the form (only) oForm.moveToInsertRow() ' Step 3 --> copy in saved values ' loop over controls again for i=0 to ccount-1 aControl = oForm.getByIndex(i) if HasUNOInterfaces(aControl, "[EMAIL PROTECTED] com.sun.star.form.XBoundComponent}") then ' get the value to set n = aControl.name ' exclude primary key field if (InStr(sKeyfieldname, n)=0) then if aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlDateFieldModel}") then aControl.Date = aVal(i) elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlTimeFieldModel}") then aControl.Time = aVal(i) elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlListBoxModel}") then oDoc.currentController.getControl(aControl).SelectedItemPos(aVal(i)) elseif aControl.supportsService("[EMAIL PROTECTED] com.sun.star.awt.UnoControlFormattedFieldModel}") then oDoc.currentController.getControl(aControl).setText(aVal(i)) else ' an EditField aControl.Text = aVal(i) end if ' let the control store it's value into the bound field model aControl.commit() end if end if next i end sub </listing> </answer> <versions> <version number="1.1.x" status="tested"/> <version number="2.2.0" status="tested"/> </versions> <operating-systems> <operating-system name="All"/> </operating-systems> <changelog> <change author-id="ms2" date="2007-09-24">Initial version</change> </changelog> </snippet>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]