Page 1 of 1

Problem with macro

Posted: Fri Mar 16, 2012 5:08 pm
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

Re: problem with macro.

Posted: Fri Mar 16, 2012 7:55 pm
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.

Re: problem with macro.

Posted: Fri Mar 16, 2012 8:20 pm
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.

Re: problem with macro.

Posted: Fri Mar 16, 2012 9:12 pm
by turi
:roll:

Re: Problem with macro

Posted: Fri Mar 16, 2012 10:06 pm
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.

Re: Problem with macro

Posted: Fri Mar 16, 2012 10:43 pm
by turi
no, this was just an example :) In fact I have not even entered the macro. :) :super: :super:

Re: Problem with macro

Posted: Fri Mar 16, 2012 10:47 pm
by turi
:roll: the element is in sub form. :)