Datensatz kopieren in Base

Antwort erstellen


BBCode ist eingeschaltet
[img] ist ausgeschaltet
[url] ist eingeschaltet
Smileys sind ausgeschaltet

Die letzten Beiträge des Themas
   

Ansicht erweitern Die letzten Beiträge des Themas: Datensatz kopieren in Base

Re: Datensatz kopieren in Base

von komma4 » Mo, 11.08.2008 00:44

...dann hast Du oDoc nicht (richtig) gesetzt.

XRay hast Du schon entdeckt?

Re: Datensatz kopieren in Base

von shorn » So, 10.08.2008 22:16

Hallo,
Du hast ein snippet gefunden - keine gebrauchsfertige Anwendung. Dir fehlt das Formular (verbunden mit Deinen Daten), mit dem Du eine angepasste Version des snippets nutzen kannst.
Ist klar, ein Formular mit Schaltfläche ist natürlich vorhanden.
Wenn Du OOoBase programmieren möchtest empfehle ich Andrews Base-Dokument.
Vielleicht finde ich dort einen Hinweis, Danke für den Link.

Grüße, Stefan

Re: Datensatz kopieren in Base

von komma4 » Sa, 09.08.2008 14:49

Lieber Stefan,

sei mir nicht böse...
shorn hat geschrieben:Woran könnte es liegen
An Deinem Verständnis!!?


Du hast ein snippet gefunden - keine gebrauchsfertige Anwendung. Dir fehlt das Formular (verbunden mit Deinen Daten), mit dem Du eine angepasste Version des snippets nutzen kannst.


Ich nutze Base praktisch nicht, habe nur wenig Erfahrung mit seiner Programmierung (a la OOoWiki Base API), arbeite eher mit Dialogen und direkt ausgeführtem SQL.
Wenn Du OOoBase programmieren möchtest empfehle ich Andrews Base-Dokument.


Viel Erfolg!

Datensatz kopieren in Base

von shorn » Sa, 09.08.2008 00:43

Hallo,

ich brauche dringend ein Makro zum Kopieren von Datensatze in Base, da ich häufiger nahezu identische Datensätze habe, die sich nur wenig unterscheiden.
Auf http://codesnippets.services.openoffice ... ToNew.snip fand ich den unten aufgeführten Code. Die Ausführung wird jedoch abgebrochen bei

Code: Alles auswählen

	oForm = oDoc.Drawpage.Forms(0)
Meldung: BASIC Laufzeitfehler: Eigenschaft oder Methode nicht gefunden.

Woran könnte es liegen:
Grüße, Stefan

Code: Alles auswählen

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, "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("com.sun.star.awt.UnoControlDateFieldModel") then
					aVal(i) = aControl.Date
				elseif aControl.supportsService("com.sun.star.awt.UnoControlTimeFieldModel") then
					aVal(i) = aControl.Time
				elseif aControl.supportsService("com.sun.star.awt.UnoControlListBoxModel") then
					aVal(i) = oDoc.currentController.getControl(aControl).SelectedItemPos
				elseif aControl.supportsService("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, "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("com.sun.star.awt.UnoControlDateFieldModel") then
					aControl.Date = aVal(i)
				elseif aControl.supportsService("com.sun.star.awt.UnoControlTimeFieldModel") then
					aControl.Time = aVal(i)
				elseif aControl.supportsService("com.sun.star.awt.UnoControlListBoxModel") then
					oDoc.currentController.getControl(aControl).SelectedItemPos(aVal(i))
				elseif aControl.supportsService("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


Nach oben