1 (edited by sonixax 2022-04-07 18:09:25)

Topic: Get parrent record id

Hi,
I just want to get parent Id of new record to run a query.

I want to have the name of parent record when creating new child record.

imagine i have a customer (john doe) and i want to add his telephone number using a new form. so I want in new form have a text box like this: add new number for: john doe

Many Thanks

Re: Get parrent record id

Hi,
Pay attention to the properties of the button defined for saving.
http://myvisualdatabase.com/help_en/script_button.html


dbGeneralTableId
Makes sense if the button has the "Save record" action assigned to it. Contains the record id, if the record is not saved, it returns -1.

dbParentTableId
Makes sense if the button has a "Save record" action. Contains the id of the child record, if the record is not saved, it returns -1.

Re: Get parrent record id

Many thanks,
But I want to have it before save anything!

I want to use it in scripts to show something on the form, no matter if save button pressed or not.


is it still stored in save button properties even before click on save button?

Re: Get parrent record id

Miracles do not happen) You can find out the last (maximum) ID
in the table you need and assume that the next one will be for a new record.
But... it won't work if the entry already existed and was deleted after and in
some other cases. And yes, it can lead to errors.
Need to see your program or example to try to help you.

Re: Get parrent record id

всем привет
попробуйте этот вариант

Post's attachments

Attachment icon test.zip 113.98 kb, 189 downloads since 2022-04-07 

Re: Get parrent record id

sonixax wrote:

Many thanks,
But I want to have it before save anything!

I want to use it in scripts to show something on the form, no matter if save button pressed or not.


is it still stored in save button properties even before click on save button?

узнать максимальный id вашей таблицы

SQLExecute('SELECT seq FROM SQLITE_SEQUENCE WHERE name="a"');

добавьте 1 и Вы получите номер будущей записи

Re: Get parrent record id

Hi Sonixax,

I want to have the name of parent record when creating new child record.

imagine i have a customer (john doe) and i want to add his telephone number using a new form. so I want in new form have a text box like this: add new number for: john doe


I'm not sure why you need the ID (which doesn't mean anything to your customer).
If, as you wrote in your original post, that you want to see the customer name, why don't you just copy it from the customer name form to the phone number form (see attached - I've chosen to put the customer name in the form caption but you could just as easily use a label or text box).
Then the whole question of getting the next record id before or after saving goes away.
Derek.

Post's attachments

Attachment icon sonixax.zip 373.46 kb, 221 downloads since 2022-04-08 

Re: Get parrent record id

Many Many thanks,
Properties of save button just helped.