Topic: saving to different table

how do i pick a name from a combo box (tied to a contact table) and want to save it to a team table as player1. would appreciate any and all help.

Re: saving to different table

Not sure what exactly you are trying to do or what help you need. Do you have the relationship defined in your database between the two tables? If you do, then all you need to do is in the Object Inspector of the combobox on your player form (Team Table) you put in the foreign key entries to the Contact Table. Then make sure you include the combobox in the "Save" action of the form. There is no reason to place the Contact Name in the Team Table. It's really not good database design to have redundant data in multiple tables. Not knowing what your design is, maybe you do need to have the Contact Name in the Team Table. If so, you'll need to add some script.  Maybe you can be a little more specific in what exactly you need help with or what you're trying to accomplish.

Re: saving to different table

the two tables are dplayer and dteamsetup. the fields in the player are the regular address information(name, address, phone,etc). the fields in teamsetup are team number, team name and player1 - player4.there are going; to be many teams. i have the relationshhip set up between the player fields and the name fields.  i have the object inspector set the way you said. i save to dteamsetup. i get the error "there is no column dplayer in dteamsetup". it probably would work if i didnt try to save the team number and name but that is what i do my search on. i hope this was able to make it a little more clear what i am trying to do. thanks again for your help

Re: saving to different table

as a side note, as i get further on in this project i am going to run into this exact same problem with another form.

Re: saving to different table

Morning LHimes,
As I understand your posts, the relationship needs to be created in the dteamsetup table pointing to the dplayer table.  The error message you are getting sounds as if you have it set up in the other direction.
However, if you have 4 players in each team and you want to select each player from the combobox, you will, in effect, need to create 4 relationships (one for each player selected).  Whilst that is possible, it gives you a problem in any tablegrids, in so far as the extra 3 relationships will be displayed by their record-id's and not the actual player names.  To get the actual player names, you will have to use calculated fields to pull in the descriptions.
I've knocked up a little example that I hope clarifies the above and highlights the problem.
I think it would be more usual to have a 3rd table (dteamplayer) to hold the details of each player in each team with a relationship between dteamplayer and dteamsetup to avoid the repeated relationships problem described above, but you may have specific reasons for not wanting to do it this way.
Hope this helps,
Derek.

Post's attachments

Attachment icon lhimes.zip 337.37 kb, 502 downloads since 2016-04-05 

Re: saving to different table

Derek's example is a good one. I went ahead and added the calculated fields that he mentioned so you can see the names of the other players in the tablegrid.

Post's attachments

Attachment icon lhimes-Revised.zip 337.61 kb, 500 downloads since 2016-04-05 

Re: saving to different table

unfortunately my version was too old to run that sample. i have the relationships set up as you said. i am enclosing my project, which is quite large and just getting started, so you can better see what i am trying to do. the forms i am currently talking about are ViewTeam and TeamSetup. the tables; are dplayer and dteamset. hope this helps

lee

Post's attachments

Attachment icon Billiards.zip 333.58 kb, 489 downloads since 2016-04-05 

Re: saving to different table

Hi Lee,
The changes you've made to your table structure that relate to players and setting up teams look fine now with the multiple relationships between dplayer and dteamset.
Can I suggest that you also delete sqlite.db - it almost certainly still reflect the old data structure before you made your changes and will give you various error messages.  Once you've done that, you should be able to add teams and players successfully.
Derek.

Re: saving to different table

deleted that file. still get the error "table dteamsset has no column nammed dplayer" when i try to save. steps to run are: add my name only to address, go to team set up, put number 1 in team number, any name in team name and pick my name for player 1. then save. then i get above error.

lee

Re: saving to different table

Hi Lee,
Strange - I think the only other change to your Billiards project that I made was commenting out the script because it was giving me an error (unrelated to your reported problem).
I've attached my working version - I'd be interested to see if you still get errors when you try it.  I added teams (and players) by clicking on "8 ball", then "Set Up Teams" and then "Add".
Derek.

Post's attachments

Attachment icon Billiards2.zip 355.96 kb, 480 downloads since 2016-04-05 

Re: saving to different table

well, i had to download the new version before i could look at it. i was hoping to get by on my free version until i could see if this was going to work out for me. yours worked fine. i tried to copy any chnges to mine but still no luck there. guess i will have to use our version. i do need the names to show up instead of the id in the grid tho. how do i go about fixing that. man, this sure would have come a lot easier 50 years ago.

lee

Re: saving to different table

Hi Lee,
I've attached your project with the names showing in the tablegrid rather than the record-IDs.  Have a look at the calculated fields in the "dteamssetup" table to see the code.
I'm pretty sure that all of the changes that have been made since you posted in the Forum would still work in Version 1.45 (the last free version) so you could 'back fit' them and it should still be okay.  Unfortunately, I don't have 1.45 on my machine any more to help out.
Derek.

Post's attachments

Attachment icon Billiards3.zip 355.84 kb, 548 downloads since 2016-04-06 

Re: saving to different table

new version of mvd looks good. the new file you sent works fine also. i realy do appreciate all of the time and effort you put into helping me. i ope i can get pretty far without any more help but i anticipate i will probably need some when i get to printing out the reports. i did notice there used to be a filter in search that would allow you search on one character.  that does not seem to be available any more. is there a work a round or fix for that. once again, thank you for your help

lee

Re: saving to different table

Hello Lee,
Not sure about the filter as I've never used 1.45.  How do you mean you search on one character?  I imagine it's still possible as Dmitry is unlikely to take functionality out.
In the versions that I've used, the search filters (wildcards, contains greater, less etc) in conjunction with incremental search has always been enough for what I need to do.
Derek.

Re: saving to different table

sorry, i lost myself for a bit there.  the filter is in the properties for a textbox. set to s% allow to search on first character. before i get any more vested in this project i need to find out how much i can do. a year in 8 ball consists of 2 seasons, each 2x weeks long. a players handicap is based on the average of the weekly score of each past 2 seasons plus all of the weeks of the current season. as he finishes the current season one past seasons scores drop off. am i going to be able to do that with this. on the scoresheet, the scores are manually put in. i found a script in the general forum to add the totals on the form but it doesnt seem to work. i dont get any errors, it just doesnt do anything.sorry for alll the questions and problems.

lee

Re: saving to different table

From what you describe, I don't see anything that MVD can't handle.
But it's vital to get your data requirements and data structure set up correctly otherwise MVD (or any other product) can't help you. 
Also, you probably need to decide how much you want to do using basic MVD or whether you want to get into scripting (which has more of a learning curve associated with it but will allow you to pretty much do anything (well, within reason!!)).
I've always found it useful to browse through the forum and download other users' projects just to get some basic ideas of what can be done, how to do it, and also to see just how complex some of their projects might be in comparison to what I'm doing.
Derek.

Re: saving to different table

I agree with Derek. I don't see anything popping out which would prevent you from completing your project. For your "s%" search, you may need to use SQL QUERY action to do that. I saw in your project where you defined totals, but I didn't see where you actually put in the calculations.

Re: saving to different table

good. what info is available on scripting. i do dl other projects and have tried to adapt some of the scripts. i have two that i am trying to get to work but i cant seem to be able to get them to do anything. they dont give any errors. they just dont work.

Re: saving to different table

I have found that Delphi Basics (http://www.delphibasics.co.uk/) is a good resource. You will also need to understand all the possible events which exist on all form objects in MVD. These events are where you will be placing your scripts. It looks like you will have a lot of calculations in your project. So for a simple form example, to add two numbers on your form and display the result on your form, a script could be as simple as

Form1.edit1.value := Form1.edit2.value + Form1.edit3.value;

You would typically place this script on your fields OnChange event. When you double click into an empty event in the Object Inspector Events tab, MVD will automatically put in the Procedure, Begin and End statements in the Script file for that particular event. You just place your code between the Begin and End statements.

You'll probably want to understand how to construct "If" statements for conditional processing and "ShowMessage" and "MessageDlg" for interacting with the user. Understanding basic SQL can help in certain situations. Since it looks like you will be totaling groups of records for averaging, you'll probably want to know how to do "SqlExecute('Select Total(Amt) from YourTable where....');"

I have only been around this product for about 5 months, including the 60 day trial. So I am by far not an expert, but I have been able to complete a fairly sophisticated project in that timeframe. Once you see how certain things work it becomes easy to repeat it for other situations. Of course, if you get stuck, you can always come back to this forum for specific problems or how to's. I am always amazed as to the help that is dedicated to it as you saw from Derek. Dimitry is the master. If it can be done, he'll have a solution. Hope this all helps. Good luck with your project.

Re: saving to different table

thanks for th resource. just downloaded their little course. that add script is one that i tried to make work for me. doesnt do anything. no errors. just kinda sits there and makes me look stupid. look forward to the delphi course. never too old to learn i guess. really appreciate the help. this place is terrific for the help provided.

lee