patapotato
New member
- Local time
- Today, 08:04
- Joined
- Oct 6, 2022
- Messages
- 15
Hi, new member here.
I have a bit of a particular task I need to do and would love some input. I've not been using access for very long (3 months) so I am still figuring this out as I go.
The actual application is very technical so I am going to simplify it a bit for this context.
I am building a recipe database. Currently all recipes are stored in excel files and the requirement is that all those files be removed and all data is stored in the access database itself (including all formulas used for calulation). Now, the recipes look a bit like general cooking recipes. There is a different excel file for every dish (spaghetti bolognese, lasagna, cottage pie etc.). The recipes list the general information one would expect: Every ingredient used, the weight/volume of each ingredient used, the total volume of the resulting dish, cooking instructions, safety instructions and so on. Now that in itself is easy to implement in access if you compare it to a recipe you might find online, but in this case the excel files offer additional features. Users can enter the total weight of the dish they want to make and the file calculates the corresponding amounts of ingredients that would be needed to prepare exactly that amount of said dish. So say you want to make 2kg of Lasagne, the recipe would automatically adjust ingredient values and tell you how much mince, carrots, onions and other you would need to make exactly 2kg of Lasagne. This is all easily done in excel, just write a little formula that calculates fields based on some ratio, some constants, some other fields etc.
I now have the task of making this all work in access using forms. Mind you that most recipes use different formulas to calculate ratios. Sometimes it is just a ratio based on the total end weight. Sometimes it is related to the amount of the other ingredients used. Sometimes there are additional variables that factor in like current humidity, pH, temperature at which it is being cooked, cooking time etc. So every excel file uses slightly different ways to calculate those fields based on the particulars of the recipe. The way I am currently prototyping this is by looking at a way to use queries to switch between formulas used in those excel files.
The idea was the following:
Make one form that works for most (if not all) of the recipes from the excel files instead of making a new form for every recipe.
Have one parent form that contains the product name and the corresponding recipeID.
On that parent form, put some subforms. One containing input variables and constants, another containing ingredients and calculated values.
The calculations for fields like weight or volume for those ingredients are done in the form of a query. Essentially, the queries take the ingredients that correspond to the current recipe and add calculated fields to it (weight/ volume etc) based on some formula; usually its just a ratio.
I then have the subform contain fields with corresponding names.
Now, if I want to switch to a new recipe, the formula changes, which would mean that I need to change the query. I do this by vba. I simply switch out the recordsource of the linked subform to a different query.
Since the names of all the controls of the form stay the same and just the way the corresponding fields are calculated in the query changes, this aparently works in access. This way I can change the formulas that are used to calculate the amounts for my ingredients simply by switching out the query that was useed to get the corresponding values. Essentially, I set the recordsource for the subforms manually according to which query relates to the particular recipeID in vba when the form gets opened.
In my testing, this seems to function, but I now have to decide how to save those queries and am not sure what the best approach would be. I have a few options I imagine. I could just make them, name them something, store the names of the queries used in each recipe in a table and then have a function that looks for the query needed in the recipe by recipeID on the parent form, sets the subform recordsource to that query and be done. The downside is that I have like 150 recipes. So I would need 150 queries that clutter my workspace. The other option I was debating was to store them as SQL strings in a table and then have the function look up that string, modify it if neccesary and then set the recordsource to that sql instruction. That would end up having my workspace be cluttered a lot less. The downside is that perhaps queries are bit more difficult to make changes to since they are exclusively accessed as a string in sql format. So any change would need to be made in sql. If I save them as access queries I can use the wizard to quickly make changes to it, test if it works beforehand etc. I think queries would also run faster if they are stored as access queries rather than sql strings in a table (at least I`ve read that somewhere) but none of them wuld be terribly complicated so I don't expect performance to matter much.
Curious what you all think, especially concerning any pitfalls I might encounter. If you have differing suggestions for how to tackle this application those are also welcome. The query calculation idea was the first one I had and I pretty quickly dismissed using calculated fields in my tables as an option but maybe there is some optimal way to do it.
greetings, and thx for any input.
I have a bit of a particular task I need to do and would love some input. I've not been using access for very long (3 months) so I am still figuring this out as I go.
The actual application is very technical so I am going to simplify it a bit for this context.
I am building a recipe database. Currently all recipes are stored in excel files and the requirement is that all those files be removed and all data is stored in the access database itself (including all formulas used for calulation). Now, the recipes look a bit like general cooking recipes. There is a different excel file for every dish (spaghetti bolognese, lasagna, cottage pie etc.). The recipes list the general information one would expect: Every ingredient used, the weight/volume of each ingredient used, the total volume of the resulting dish, cooking instructions, safety instructions and so on. Now that in itself is easy to implement in access if you compare it to a recipe you might find online, but in this case the excel files offer additional features. Users can enter the total weight of the dish they want to make and the file calculates the corresponding amounts of ingredients that would be needed to prepare exactly that amount of said dish. So say you want to make 2kg of Lasagne, the recipe would automatically adjust ingredient values and tell you how much mince, carrots, onions and other you would need to make exactly 2kg of Lasagne. This is all easily done in excel, just write a little formula that calculates fields based on some ratio, some constants, some other fields etc.
I now have the task of making this all work in access using forms. Mind you that most recipes use different formulas to calculate ratios. Sometimes it is just a ratio based on the total end weight. Sometimes it is related to the amount of the other ingredients used. Sometimes there are additional variables that factor in like current humidity, pH, temperature at which it is being cooked, cooking time etc. So every excel file uses slightly different ways to calculate those fields based on the particulars of the recipe. The way I am currently prototyping this is by looking at a way to use queries to switch between formulas used in those excel files.
The idea was the following:
Make one form that works for most (if not all) of the recipes from the excel files instead of making a new form for every recipe.
Have one parent form that contains the product name and the corresponding recipeID.
On that parent form, put some subforms. One containing input variables and constants, another containing ingredients and calculated values.
The calculations for fields like weight or volume for those ingredients are done in the form of a query. Essentially, the queries take the ingredients that correspond to the current recipe and add calculated fields to it (weight/ volume etc) based on some formula; usually its just a ratio.
I then have the subform contain fields with corresponding names.
Now, if I want to switch to a new recipe, the formula changes, which would mean that I need to change the query. I do this by vba. I simply switch out the recordsource of the linked subform to a different query.
Since the names of all the controls of the form stay the same and just the way the corresponding fields are calculated in the query changes, this aparently works in access. This way I can change the formulas that are used to calculate the amounts for my ingredients simply by switching out the query that was useed to get the corresponding values. Essentially, I set the recordsource for the subforms manually according to which query relates to the particular recipeID in vba when the form gets opened.
In my testing, this seems to function, but I now have to decide how to save those queries and am not sure what the best approach would be. I have a few options I imagine. I could just make them, name them something, store the names of the queries used in each recipe in a table and then have a function that looks for the query needed in the recipe by recipeID on the parent form, sets the subform recordsource to that query and be done. The downside is that I have like 150 recipes. So I would need 150 queries that clutter my workspace. The other option I was debating was to store them as SQL strings in a table and then have the function look up that string, modify it if neccesary and then set the recordsource to that sql instruction. That would end up having my workspace be cluttered a lot less. The downside is that perhaps queries are bit more difficult to make changes to since they are exclusively accessed as a string in sql format. So any change would need to be made in sql. If I save them as access queries I can use the wizard to quickly make changes to it, test if it works beforehand etc. I think queries would also run faster if they are stored as access queries rather than sql strings in a table (at least I`ve read that somewhere) but none of them wuld be terribly complicated so I don't expect performance to matter much.
Curious what you all think, especially concerning any pitfalls I might encounter. If you have differing suggestions for how to tackle this application those are also welcome. The query calculation idea was the first one I had and I pretty quickly dismissed using calculated fields in my tables as an option but maybe there is some optimal way to do it.
greetings, and thx for any input.