Problem with macro

Creating and using forms
Post Reply
turi
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Problem with macro

Post by turi »

hello all. It 's my first post here.
Sorry if I do not speak well but I'm using an online translator.
i have this macro:

Code: Select all

REM  *****  INSERIRE VOTI  *****

Global nCursor As Long
Global sTextBox As String
Global oText As Object

Sub SingleLine_TextBox_StoreCursor (oEvent As Object) 'Text Box > Events > When Losing Focus 
   sTextBox = oEvent.Source.Model.Name
   oText = oEvent.Source.AccessibleContext
   nCursor = oText.CaretPosition
End Sub 

Sub SingleLine_TextBox_Insert_Quattro (oEvent As Object) 'Button > Events > Execute 
   oText.insertText(("15/01/12"),nCursor)
   oForm = oEvent.Source.Model.Parent
   oForm.GetByName(sTextBox).commit()
   IF oForm.isnew THEN oForm.insertRow() ELSE oForm.updateRow()
End Sub 
only works if you point the cursor in a field Mainform.
I have a main form and subform, I would like the date (eg 1/15/12) is incorporated in the subform that is connected to the main form by relationship (Last Name, First Name, Date of Birth)
Mainform = Full name, date of birth
Subform = Full name, date of birth, presence)
I would make sure that if I click the button I insert the subform name, first name, date of birth, presence (which is imposed directly in the macro).
Thanks for the answers you give me.

P. S. forum in my country do not know an answer.

My database is with mysql
openoffice 3.1 windows xp
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: problem with macro.

Post by B Marcelly »

Hi,
If your text box is in a sub-form you can only get it from the sub-form, not from the main form.
It should work if your button is also in the same sub-form.
Otherwise you must first get the sub-form from the main form, with getByName() method.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: problem with macro.

Post by DACM »

Welcome turi,
turi wrote: only works if you point the cursor in a field Mainform...
I have a MainForm and SubForm, I would like the "date" in the SubForm
This code looks familiar. But this is a difficult issue to sort out, because it may be:
1. a database design issue requiring database normalization
2. an ISO date format issue if using DATE data types
3. a SubForm link issue, simply requiring a oForm.Reload() in order to see the results automatically copied to the SubForm.
4. additional code to access and clone data to a Text Box or Date Field on the SubForm (as B Marcelly outlined above)

So it would be best to post a copy of your .odb front-end file for examination.
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
turi
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Re: problem with macro.

Post by turi »

:roll:
Attachments
Nuovo databaseA.odb
(12.52 KiB) Downloaded 129 times
openoffice 3.1 windows xp
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Problem with macro

Post by B Marcelly »

Open your form document in Design mode.
Open the Form Navigator. You can see that button Pulsante1 is an element of MainForm. Drag Pulsante1 to SubForm.
Now the code should work.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
turi
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Re: Problem with macro

Post by turi »

no, this was just an example :) In fact I have not even entered the macro. :) :super: :super:
openoffice 3.1 windows xp
turi
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Re: Problem with macro

Post by turi »

:roll: the element is in sub form. :)
openoffice 3.1 windows xp
Post Reply