Problem with macro

Creating and using forms

Problem with macro

Postby turi » Fri Mar 16, 2012 5:08 pm

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   Expand viewCollapse view
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
turi
 
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Re: problem with macro.

Postby B Marcelly » Fri Mar 16, 2012 7:55 pm

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.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
B Marcelly
 
Posts: 774
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: problem with macro.

Postby DACM » Fri Mar 16, 2012 8:20 pm

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.0.x; LO 4.1.x; Windows 7 64-bit
Wizard: Automated 'split' HSQL database template; Warning: Avoid embedded databases
Soli Deo gloria
User avatar
DACM
Volunteer
 
Posts: 1072
Joined: Tue Nov 03, 2009 7:24 am

Re: problem with macro.

Postby turi » Fri Mar 16, 2012 9:12 pm

:roll:
Attachments
Nuovo databaseA.odb
(12.52 KiB) Downloaded 59 times
openoffice 3.1 windows xp
turi
 
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm

Re: Problem with macro

Postby B Marcelly » Fri Mar 16, 2012 10:06 pm

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.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
B Marcelly
 
Posts: 774
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Problem with macro

Postby turi » Fri Mar 16, 2012 10:43 pm

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

Postby turi » Fri Mar 16, 2012 10:47 pm

:roll: the element is in sub form. :)
openoffice 3.1 windows xp
turi
 
Posts: 4
Joined: Fri Mar 16, 2012 4:58 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 4 guests