1 (edited by papafrankc 2021-10-01 03:16:33)

Topic: Report on content of one field in a table

Hi Everyone,
I have  table with a field called spare
That field has 2 values Installed and Spare
.
I would like to print 2 reports - one with only records containing Installed and another with only records containing Spare.
Basically I would like to be able to filter a record in a table for the value in the field. I'm thinking that this ability to filter data could be useful going forward.
.
I have been told to use Report(SQL) but I have been unable to write a query that will do that for me.  My coding skills are limited :(
.
I have tried to do it using REPORT and REPORT(SQL) without success.
-------------------
One more comment, I have been able to use the filter option in a tableGrid to get only the records I referenced above, however I have not been able to transfer those records to a report.
.
Thoughts will be appreciated.
Thanks, Frank

Re: Report on content of one field in a table

papafrankc,
.
I have an example based on my interpretation of your question.  Maybe this gives you some ideas.

Post's attachments

Attachment icon 7774_report-two-value-field_papafrankc.zip 328.13 kb, 178 downloads since 2021-10-02 

"Energy and persistence conquer all things."

Re: Report on content of one field in a table

JoshuA,
Thank you so much.  Your solution looks like it should work for what I'd like to do.
.
And I think it may solve 2 issues that I've been thinking about.
1 - The Installed/Spare issue (my original question) and...
2 - How to store a value in a field using a combobox.  This one I hadn't asked about but recently I've been wondering if it could be done without creating a separate lookup table for stuff like YES/NO, INSTALLED/SPARE, MALE/FEMALE...etc
.
Currently with my Installed/Spare lookup table it requires me to access and manipulate 2 tables.  As opposed to having one field for Installed/Spare in my main Equipment table.  I believe this option will simplify things for me now and going forward.  I also have a lookup table called 'Priority' with HIGH, MEDIUM and LOW.  Using a combobox for these kinds of entries sounds like a good option for me.  THANK YOU smile
.
Frank

Re: Report on content of one field in a table

JoshuA,
I ran into an issue with the combo box on Form 2.
Everytime I would ADD or EDIT an entry it would add an extra Installed/Entry to the combo box.
.
So I added this line to the script file:
form2.ComboBox1.Items.Clear ; // ADDED to clear the combo box
Now it reads:
form2.ComboBox1.Items.Clear ; // ADDED to clear the combo box
    Form2.ComboBox1.Items.Add('Spare');
    Form2.ComboBox1.Items.Add('Installed');

.
So everything is looking good so far.
Thanks again for your help
Frank

Re: Report on content of one field in a table

JoshuA,
I ran across something that you may be able to help me with.
I have implemented the Installed/Spare dropdown into my program and it works great.
Here's my scenario:
I add a new record using the dropdown cboSparePart.
If I choose 'Installed', it adds it to the hidden field EqSparePart. That's perfect.
However, when I save the record and then open it up again, the (cboSparePart) dropdown is empty.  When in reality the hidden field EqSparePart already has data in it from the previous activity.
.
So my question is, is there any way for the dropbox cboSparePart to show the value that was previously set?
.
Thanks
Frank

Re: Report on content of one field in a table

papafrankc,
.
I didn't test out the bugs, but you done a fine job with squashing them already.  Thanks for sharing your changes too.  I just hope I can remember them whenever I need to do this again in the future.
.
I'm not as experienced as some of the other folks here.  Just trying to give you some ideas to try because I have received a lot of useful help and ideas whenever I get in a pinch.  With that being said, anything you get from me needs to be extra tested!  LOL
.
As for your 2nd question, the only way I can think of for doing this is to copy back from the (hidden) text field when the user is editing via a ShowRecord condition.
.

procedure Form2_OnShow (Sender: TObject; Action: string);
begin
    form2.ComboBox1.Items.Clear ; // ADDED to clear the combo box
    Form2.ComboBox1.Items.Add('Spare');
    Form2.ComboBox1.Items.Add('Installed');

    // For editing
    if Action = 'ShowRecord' then
        Form2.Combobox1.Text := Form2.Edit1.Text;
end;

.
Again, I haven't tested it for use.  But it seems to work on the first attempt.  I have also changed this in my example project in case it's necessary for someone else to reference.

Post's attachments

Attachment icon 7774_report-two-value-field_v2_papafrankc.zip 328.68 kb, 186 downloads since 2021-10-03 

"Energy and persistence conquer all things."

Re: Report on content of one field in a table

JoshuA,
It works great, thank you.  Pretty simple, just a couple of added lines of code.
.
FYI - I've been working on adding the fix for the last few hours and it would not work in my program.  Very frustrating!!!  I followed your example to the letter, or so I thought?? And it still wouldn't work.
But just now I removed my combo box and replaced it with a new one.  And I applied the fix.  And VIOLA.....it's working.
I'll be darned if I know what I did differently but I'm not complaining because it works.
.
Tomorrow I'll go back through my code and see if I can figure out what I did differently this last time.
.
Thanks again, I keep on learning new stuff and that's a good thing.
Frank