[Solved] Current record ID in Form

Creating tables and queries
Post Reply
balamut
Posts: 8
Joined: Mon Aug 15, 2016 3:04 pm

[Solved] Current record ID in Form

Post by balamut »

Hello,

i didnt find how to use ID of current record in Form.

I am thinking about queries, working like this :

Code: Select all

select STATUS_TEXT, STATUS_ID 
   from QA_STATUS 
   where STATUS_ID >= (select STATUS from QA where QA_ID = %CURRENTID%);
(%CURRENTID% represents unique ID of current record editable in Form, QA is table edited by Form)

Do somebody know the simple way how to use ID of current record in other Form fields?
Last edited by balamut on Wed Aug 17, 2016 10:01 pm, edited 1 time in total.
OpenOffice 4.1.2 on Windows XP, HQSL 2.3.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Current record ID in Form

Post by RPG »

Hello

When you study this tutorial of Arineckaig then it is maybe possible for you to build forms, It learns you how to filter forms.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
balamut
Posts: 8
Joined: Mon Aug 15, 2016 3:04 pm

Re: Current record ID in Form

Post by balamut »

Great tutorial thank you very much...

...but really doesnt exist some simple way how to use something like %CURRENTID% directly (or indirectly, for instance use macro variable) in SQL statement defining field data?

ill try to explain better the statement in the first post. Record in QA table has some status (integer STATUS), decreasing of which is forbidden. The statement is used to create listbox, which offers only valid values. The subform solution of this problem,if really possible seems like overkill, because of in form will be more context-dependent listboxes than this one.
OpenOffice 4.1.2 on Windows XP, HQSL 2.3.2
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Current record ID in Form

Post by RPG »

Hello

Maybe you can use a main-form and a subform in one form-document. This form-document can be stored in the databasedocument or can be a stand-alone-form.

Learn to use the form-navigator. When you can use the form-navigator then it is maybe more easy to understand the difference between all the forms we can use.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
balamut
Posts: 8
Joined: Mon Aug 15, 2016 3:04 pm

Re: Current record ID in Form

Post by balamut »

Subforms are no way in this case. I had written a small macro, which sets variables from current record.

Code: Select all

REM  *****  BASIC  *****
Global MyCurrrentID
Global MyCurrrentPLATNE

Sub Main
End Sub

Sub Show_ID
    MsgBox "RECORD ID: " + MyCurrrentID + Chr$(10) + "PLATNE: " + MyCurrrentPLATNE
End Sub

Sub SET_MyCurrrentID_From_Form (oEvent As Object) 
       Dim IoForm   
        IoForm = oEvent.Source
	MyCurrrentID = IoForm.Columns.getbyName("ID").Value
	MyCurrrentPLATNE = IoForm.Columns.getbyName("PLATNE").Value
End Sub
SET_MyCurrrentID_From_Form is as Form event (third from end, i am not sure how to translate back to en)
This seems to work fine, global values are usable in the whole form

Question is now clear: How (if possible) to use these variables in that listbox query.

When i try simply
Image
request fails with "parameter marker not allowed" error

Please have somebody any idea how to do this better
or
prepare desired listbox using another way on this level?
OpenOffice 4.1.2 on Windows XP, HQSL 2.3.2
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Current record ID in Form

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
balamut
Posts: 8
Joined: Mon Aug 15, 2016 3:04 pm

Re: Current record ID in Form

Post by balamut »

Great idea, thanks very much. If i understand right, priciple of the solution lies on stored statement - have to explore this idea more.

For my current purpose shoul be probably better to use simple macro, sketched in my last post, because offers context - sensitive control over whole Form. Having current record values in global variables seems to allow direct setting of form elements attributes to read only creating buttons with record-specific actions (as clone, search similar), etc...

I am not sure, if this is solution or workaround, but i am going to mark this thread as solved.

Thank you all very much
OpenOffice 4.1.2 on Windows XP, HQSL 2.3.2
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Current record ID in Form

Post by Villeroy »

balamut wrote:Great idea, thanks very much. If i understand right, priciple of the solution lies on stored statement - have to explore this idea more.
It is the exact same "power filtering" technique suggested by RPG, documented in detail by Arineckaig. It is simple, flexible, works without stupid Basic code. It requires that you store filter criteria somewhere. Stored filter criteria can substitute query parameters. Stored filter criteria can be used for filtering and conditional calculations in subforms and all kinds of reports.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply