Topic: Change behavior of fields in another form based on id of another table

Good evening,

I'm scratching my head over one bit tricky problem that I'm facing these days.
I've tried numerous solutions but I didn't manage to find a correct way.

So first things first we have 3 tables (models, modeltypes, meters) and 3 different forms. Now what I want to do is when a combobox on form 3 (meters) which is for the model name that has a specific model type changes based on the selection, I want to hide a specific field(s) on form 3, i.e. if the modeltype is black and white then hide the field on form 3.

I attach a sample project to be more helpful.
(It contains another forms and tables I was experimenting, but the forms that I want to work are form4, form5 and form6)

Thank you for any advice and help anyone can provide.

Post's attachments

Attachment icon combobox_selection (2).zip 338.7 kb, 132 downloads since 2022-08-12 

Re: Change behavior of fields in another form based on id of another table

ktommy wrote:

Good evening

Вы хотите создать поиск по таблице?
Do you want to create a field search in a table?

Re: Change behavior of fields in another form based on id of another table

Hi Ktommy, Vladimir
I'm not quite sure I understood your attached example but it seems, at its core, that you want to hide / reveal various objects depending on a selected value in a combobox or tablegrid.
It doesn't matter whether the objects are on the same Form or on a different one - the syntax is the same.
Have a look at the attachment for some suggestions.
In Selection1, depending on the value selected in the combobox, diffferent tablegrids are hidden / revealed, a button is revealed and on a second Form, one of the fields is hidden.
In Selection2, depending on the value selected in the combobox, wholly different Forms are revealed so you don't have to worry about what objects are made visible or revealed;  obviously there is a bit more work to creating Forms specific to combobox selections (but you can copy / paste objects between forms so it's pretty quick) and it simplifies the script.
Like most things in MVD, there's usually a choice of how to achieve something.
One 'tip' - if you have a number of objects to be made visible / invisible, try placing panels on the Form and then adding objects to that panel.  Objects placed in panels are subordinate to the panel so you only need to make the panel visible / invisible rather than all the objects within that panel;  it can reduce the amount of code you need to write significantly.

Hope this helps,
Derek.

Post's attachments

Attachment icon combobox selection.zip 676.02 kb, 144 downloads since 2022-08-13 

Re: Change behavior of fields in another form based on id of another table

Good morning everyone and thank you for your answers.

As you can imagine I've just started the programming and every start is difficult, so I try to experiment with different stuff to obtain experience. I try to ask for help only in a situations that I'm cornered and I'm grateful for every help.
derek thanks once again for your explanation and your tips at thinking of how to solve the problems. Your example is great and it helped me figure it out on my other problem that I had. But this time maybe I was not mentioned clearly what was my idea and if it is a pain to create id I'll just use a simple checkbox and won't disturb anyone else.
So what I want to do is based on the machine type that correspond to a model I want to hide fields at another form. I thought that by using a combobox and the value that is used to store when adding a record to a table should work but then I noticed that it didn't because it has to read not the combobox value but the modeltype_id based on a model that is attached to. So the code should be something like:

if form1.tablegrid.columnname.id = 1 then form2.edit1.visible := false;

but as I mentioned earlier I'm novice and hasn't fully update my knowledge of programming haha.

Thank you in advance once again.

Re: Change behavior of fields in another form based on id of another table

Hi,
Attached are a couple of examples of how you might do the sort of thing you're asking about (one uses panels, one uses tab sheets / page control). 
In both instances, selecting a record from the tablegrid displays different edit fields depending on 'machine type' or in the case of adding a new record, it is only after the machine type has been selected that a different selection of edit fields are presented.
The link through to the machine type can be derived either from Form1.tablegrid1 or from the machinetype that is displayed on Form2.  If your processing flow uses the same form that you use to add/edit records (ie Form2) then it is both easier and more efficient to pick the 'machinetype' value from there (it has to be there because that's how you would have selected the relevant 'machinetype' from a combobox in the first place when creating the 'model' record). 
If your processing flow doesn't use the form that you add/edit records on, then use Form1.tablegrid1 instead to derive the 'machinetype'.
Obviously the sample data I've used won't relate to your application but the principle is the same. 
Derek.

Post's attachments

Attachment icon ktommy examples.zip 682.31 kb, 164 downloads since 2022-08-13 

Re: Change behavior of fields in another form based on id of another table

Derek good afternoon,

Hope you're all fine and healthy.
Sorry for the delayed replay but due to an illness I had to rest for a week. But now I've returned full of energy.

You've just solved the problem once again and I cannot find the words to thank you.
It's exactly what I was looking for.

There's one thought that crossed my mind that I used to do when I was creating my first database on MS Access is that when you select an item from the combobox then it would autofill the textboxes based on a Query (i.e. customer name, address, etc.)  with the rest of the information. I hope that I state it clear for you to understand.
I checked the in settings if there is any available option for it but I couldn't find it. I don't know if this will work without using script and if it is hard to do than don't bother yourself, you have already helped me a lot. It's just an idea nothing more.

Thank you once again.
Enjoy the weekend.

Re: Change behavior of fields in another form based on id of another table

Hi,
If you could attach a sample project showing exactly what you're after, it would help to give you a more focused answer.
However, there are a couple of options that might be relevant (please see the attached).
Autofilla
1.  for a new record, either open the combobox  and select the customer or start typing the name of the customer.
2.  once your customer has been selected from the combobox, any other existing fields that you want to see from the selected customer record can be  retrieved using a script;  this is only relevant when adding a new invoice as it picks additional fields up automatically if you are in 'edit' mode.

Autofillb
1.  format the combobox so that not only the customer name but also the customer town and phone are available);  the added advantage of this is that you can start typing the name of the customer OR start typing the town  OR start typing the phone no'.  So if you want to see all your customers based in a certain town, for example, it is a very easy search.
2.  there is no script involved with this option.

But as I said at the start, depending on exactly what your scenario is, neither of these may be quite what you're after.
Derek.

Post's attachments

Attachment icon auto fill options.zip 676.85 kb, 142 downloads since 2022-08-20 

8 (edited by ktommy 2022-08-20 21:20:28)

Re: Change behavior of fields in another form based on id of another table

Hello Derek,

You are right I should have attach the sample project, but for yet another time you gave me the answer with the autofill A sample. That's exactly what I was looking for by using SQL command but I hadn't manage to find the correct expression.

Hope that I won't  bother you more with my annoying questions ha ha ha.

Have a goodnight.

Tommy.