Adding a 'Heading 1' to a Word 2010/13 Doc in Alphabetical Order - ms-word

I'm operating in Word 2013 and 2010, so I can use code that works in either. I'm trying to create a word document to keep track of my recipes. At its most basic I want to have a TOC that updates based on headings. I also want it to have any category I want (eg: Appetizers, Drinks, Entrée, etc...) ordered alphabetically. Under each category I have tables. Each recipe gets a table that has it's name, directions, notes, tags, and potentially a picture. The second cell has another two column table inside of it that contains the quantity and name of each ingredient necessary for the recipe.
I have all of that so far and I'd like to automate adding new categories and recipes. Currently, I have to find the category, then scroll down to find where the name goes alphabetically and insert a quick table I made. I then fill in the info.
I'd like to be able to search the document for each category name, then insert the new category wherever it belongs, with a space before and after it. I found that my tables give me trouble if I don't have a space between everything. It tries to pull anything it's touching into the table and merge them.
I wanted to give the backstory, so you'd know where I was going to go eventually and could provide help that fits better with what I need. After I can add a new category, I plan to use vba to organize each table alphabetically by the name in the first cell of each table. It will also help when I start adding sorts to it. Eventually, I'd like to be able to sort it to say, only display recipes from a certain person, or display my frequently used recipes. I'd then have it either hide all the others or create a new doc with just these. So thanks for the help. Below I'll post the code I most recently tried. I tried a few other variations of this same code and keep getting an 'expected end of statement. I've gotten other errors when trying other variations of it, but this is the best I can come up with on my own.
Private Sub UserForm_Initialize()
For Each cat In ActiveDocument.Styles = "Heading 1"
lstCat.AddItem (cat)
Next
End Sub
I have a form called frmAddCategory I'm using as a test. I was going to have a listbox lstCat to show every category with the style heading 1. I have a textbox called txtAdd to type new ones and a cmdAdd button to add it to the form.
Edit: I've been playing around with my macro recorder after finding out about outline view mode. I set it to show only 'heading 1' level and selected the ones I wanted, not selecting the appendix or reference. Then I went to the home tab and sorted paragraph by ascending alphabetical order. I got some code I believe I can use to get it to run in VBA. However, it's not a complete fix as I don't want to select the last two with heading 1. It also works if I manually select the tables under each heading 1, but I can't set the spacing before and after. I'd like each heading and the tables under them to have a space or two between each for looks and editing purposes.
Also, if someone is going to give my question a negative rating, then please post a comment explaining. As far as I can tell from the faq about the forum and the other questions I've seen, it is a well posed question. A clear title, a good explanation of the problem, code examples, research. So if I am doing something wrong, please inform me, so that I can correct it.

first thanks for your bit about macro recorder and outline mode, I have been trying for long time to fill a list box with selection.text between two HeadingLevel(1) headings.
now to yours, sorry I can't think of way to do in word. BUT it would be real easy in Access. one table of categories like called tblCategories another for recipes tblRecipes. To make real easy, when the use autoID on ALL tables. But to avoid LOTS of headaches for tblRecipes rename its autoID to RecipesID same for other tables. in table of recipes you can use a memo field to hold large amount of data. the spot for text in Heading would be put in one field of the tblRecipes. once you have tables looking to have a field for each item you want to track. hit save, then use wizard to create a form based on table. repeat for all tables you want to have it real easy to put info into any table.
1.reportTOC based on query of Every Heading you want, can preview or print as want. reportByCategory and so on reports are sorted a to z unless you want to sort by Owner, then recipe all auto sorted a - z.
report wizard to get hard copy. if you want to sort real easy, built in. also if want to be able to pick all recipes for a holiday real easy, one table tblHolidays. one tblHolidayRecipes fields autoId (not used by you anywhere but needed), fldRecipesId (holds RecipesId) , fldHolidayId (holds HolidayId). the wizard will show how to get only what you want. in access 2013 you can include pix of food or.

Related

MS Access Form and Tables

I have a specific question regarding the utilization of three tables in a database. Table 1 is called Personnel, and lists the names of the staff.
Tables 2 and 3 are identical, just listing two different types of overtime (long and short), along with the hours of the OT, Date of the OT, and Assigned to/Picked fields that are empty.
Here is the idea, I just dont know how to implement it. I would like to create a form for people to enter their OT picks, then automatically move to the next person on the list. So Rich Riphon, as an example, would be up first, would click on the link I would send, and a form would open up, showing his name, populated by the first table, and showing two drop down menus, populated from the Long OT and Short OT tables. He would select one from each (or None, which would be a option) and Submit it.
The form action would be to place his name in the Assigned field for the OT he picked, and place a Yes in the Picked field.
When the next person in the list opens the form, it has moved down to number 2 on the Personnel list, Cheryl Peterson, and shows her the remaining OT selections (excluding those that have a Yes in the Picked column).
Any suggestions or comments or better ways to do this would be appreciated.
First, I don't think ms access would be able to (easily) kick off the process based on a hyperlink. You may be able to do something by passing a macro name to a cmd prompt but it would take some mastery to get it working properly. Could you instead create a login form to get the current user? If you do that you don't really need to display the personnel list, just keep track of who has not yet responded to the OT request. Essentially at that point all you would need on your form is a listing of the available OT and a button that creates the assignment. Also it may be easier (and a better design) to only have one table for the OT listings and add a column for the type of overtime (long/short).
What if Cheryl isn't the 2nd person to get the form? Your concept goes out the window.
Instead, I would keep a table of all user names, and their security level. managers can see everything, individual users can only see their record. This would be done by using a query behind the OT Picks form, and either filtering by the current user or not filtering at all. I have done many of these types of "user control" databases and they all have worked well.
As for the actual OT tracking, I agree with Steve's post in that it should be done in one table This would be the preferred method of a concept referred to as "normalizing data". You really want to store as little data as possible to keep the size of your database down. As an example, your Login table would have the following fields:
UserID
FirstName
LastName
SecurityLevel
Address1
Address2
City
State
Phone
Etc... (whatever relevant info pertains to that person)
Your OT table would look like this:
UserID
OTDate
OTHours
OTType
Etc... (whatever else is relevant to OT)
You would then join those 2 tables on the UserID fields in both tables any time you needed to write a query to report OT hours or whatever.

APEX - Can a Tabular Form with its MRU functionality have filtering functionality like an Interactive Report?

What I really need is a Tabular form that allows me to update multiple rows at a time while being filterable like an Interactive report. Any chance this is even remotely possible?
I would also like to hijack the row checkboxes on a tabular form that appear when the 'delete' functionality is activated and use them to select which rows get assigned a to a group based on a common attribute. (i.e. My table contains parts in my inventory and I need to be able to assign parts with common attributes to a group for processing)
Perhaps a group-by function that creates a new row in a 'Group' table with the group as the PK and the parts assigned to that group as a list or something...?
Thoughts? I am kind of at a loss...
It's really not that hard :) You can easily transform an IR into a pseudo-tabular form. And even though there are always more stylish and elegant solutions, those usually involve lots of javascript and/or plugins. They're nice, but not always what you want or need of course.
So how to manipulate your output? Use the APEX_ITEM api!
Quick example. I have an ir built on emp. I added a checkbox and textbox.
select empno, ename, deptno,
apex_item.checkbox(1, empno) empno_selected,
apex_item.text(2, ename, 10, 10) ename_edit
from emp
Don't forget: in the column attributes, set Display text as to Standard Report Column. If you don't, the output will be in plain text. Since apex_item generates html code, you don't want the plain text of course :)
Now, to be able to perform DML based on the actions you do in those generated fields, you will need a process. Let me start off by pointing out though that the generated items are stored in application variables, namely in arrays in APEX_APPLICATION.
Take note of the behaviour of checkboxes: only ticked boxes will have their value stored in the array!
As an example, i've made this small On Submit process (also adding a SUBMIT button on the form to actually perform the submit...)
for i in 1..apex_application.g_f01.count
loop
insert into empselected(empno, selectiondate, ename_changed)
values(apex_application.g_f01(i), sysdate, apex_application.g_f02(i));
end loop;
This will loop over the records with the checkboxes ticked, and insert them into some table. For example, i ticked the box with KING and edited the textfield. See record nr 2 (1 is from a previous action ;))
It's not all the way there yet though. You still miss out on the functionality of a tabular form and it's processes, and things like optimistic locking. If you want to stay with tabular forms, you can also, for example, check out this link. There have also been some questions here about writing your own mru processes etc, like this one ;)
It is possisble, using the same tabular form.
Create an item (text item) in the tabular form region.
Create a submit button (Create a button displayed among this region's items)
Modify the where clause in the tabular form region source
For Example, you need search by customer name:
WHERE lower(CUSTOMER_NAME) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
If you need to search for other field only add other condition to the where clause
WHERE (
lower(CUSTOMER_NAME) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
or lower(CUSTOMER_address) LIKE '%'||lower(nvl(:PXX_SEARCH,CUSOTOMER_NAME))||'%'
)
Simple and use the same tabular form.

How can I create a new primary key in a FileMaker table and then modify an existing relationship to be based on the newly created key?

I have quite the request. A developer created our database that has multiple Layouts with a relationship tree that is very messy. Had another developer come in, take a look at it, he said that it would be too time consuming and painful to deconstruct our system, consider creating a script for now so that you can work around it until it can be fixed. Here's the dilemma: I've got information on one page that is supposed to reference information on a number of different pages utilizing tabs and portals. However, all the information is linked to a username. This username is not static/serialized or what have you. Therefore, if the issue is not caught right away a great deal of information can be linked to this person's 'page'. If the name is incorrect and someone tries to alter the username even slightly, it breaks that relationship and starts a new one. The information does not disappear, but it is basically sitting in limbo somewhere until you change the name back to the original. I've actually tried exporting the information, changing the information that doesn't match, i.e. changing a name from Jon.Smith to John.Smith, and then importing the information to a new 'page' for that person with unsuccessful results. Which brings me to my question, is a script going to be able to fix this problem? Likewise, are there any suggestions to how to create this script? I apologize, but I have very little experience with DataBase management at all, and am not sure why this project fell upon me. Any help would be GREATLY appreciated.
Well, as a general answer, just about anything that a user can do in FileMaker (and by user, I mean non-developer, so activities such as defining the database structure, writing scripts, etc., are excluded) can be scripted. So if you're able to "solve" the problem by resetting a field's value, for example, then, yes, a script can do that.
Regarding your specific trouble, a script probably doesn't need to export the records, but could reset the values for the field within FileMaker. This could be done either by looping through the records that need to be changed or by using the Replace Field Contents script step. So a script could do something like this:
Go to Layout[MyLayout] // Go to a layout that is attached to the table you need to search.
Perform Find[Restore] // Restore a find that will show the records you need to change.
Replace Field Contents[Table::Field; "New Value"]
Offering more advice than this would require actually seeing the database and understanding more about your specific needs.
wchsTech4, you are in luck because your problem is easy to fix. You don't even need a script.
BACK UP YOUR FILE(S) FIRST. Then:
1) Create two new fields:
id (person table)
Options for id: Auto-enter serial number
person_id (the table related to person)
2) Generate serial numbers for the new id field in the person table.
Navigate to the person layout.
'Records' > 'Show all records'
Click in the id field and select 'Records' > 'Replace field contents.'
Choose 'Replace with serial numbers' and accept the defaults. Be sure to check the box to update your next serial number.
3) Place the serial numbers you just generated in the related table.
Navigate to the related layout.
'Records' > 'Show all records'
Click in the person_id field and select 'Records' > 'Replace field contents.'
Choose 'Specify' next to 'Replace with calculated results.'
In the drop down on the top left, select the related person table.
Double click the id field (your calculation should be person::id, with person replaced with the name of your table).
Click 'OK' and then 'Replace.'
4) Change the relationship.
Select 'File' > 'Manage' > 'Database.'
Navigate to the relationship tab.
Change the relationship from being based on name to id.
5) Test everything. Should work.
There is a chance that your related records are being created in such a manner that you also need to modify a script, website, or something else not mentioned here to have your fix work going forward. That is important to investigate.

One (probably unbound) Access 2003 form to create multiple records

I've been recruited to work on a form for tracking specimens. Each specimen is associated with a subject; each specimen also has a particular slot in a 9 x 9 storage box. For ease of data entry, I think it would be best if the Access form mirrored the box itself (and the paper forms that will be used to enter data into Access): nine columns by nine rows, with each element consisting basically of a text box for the specimen ID. This is basically how I'd like it to look:
So the data entry person would essentially type in the box number and specimen IDs, then click "Create Records" to pop all of those records into existence (you can see some other stuff going on here, but that's not really important right now). I'm not really sure about the best way to code this, however. Right now, the best process I can think of is to: 1) run an insert query to create the box if it doesn't exist, 2) run an insert query to create the subject (person), if it doesn't exist, and 3) run an insert query for each specimen, hard-coding in its row and column (e.g. box_col = 'A', box_row = '1').
Note: the subject ID and specimen ID would both be parsed out of the ID field - it's goofy, not my idea, but that's how it's set up. I can handle that, though.
This is a certainly a kludge, but I'm not sure what else to do and most of what I've googled up hasn't been pertinent to multiple-record creation from a single form. Is there a better way to do this? Should I simply abandon the idea and go with a more traditional bound subform approach?
This could be all done in a sub form - however, I assume for simplicity (less clicks, easier user experience, and intuition) you've designed it so that the end user sees everything he /she need to enter. There is nothing wrong with doing it this way. Once the data is all entered just have a button on the form that does the multiple inserts at once.
Start at 1 and include 9 iterations each time issuing a new INSERT statement.
Once the statement has been completed I would personally put a little check mark next to each row so that if an insert succeded it would check it true, else false. You could be nifty and use a green image / red image. After it has completed the process all fields should be cleared allowing additional entry.
I don't see an issue with what you have.
FRIG. I just lost ten minutes of typing. This is why I don't care for web based forms. Although to be fair this is the first time this has happened on StackOverflow.
Do you really need to view the data later in the same format as it's entered. If they can just view regular subforms that's at least half the work as you no longer need to do updates of this form.
Also note that there is a lifetime amaximum of 768, if I recall correctly, controls per form. 9 x 9 x 2 is 162 so you'll be ok there. However if you decide to delete and recreate lots of cotrols you could be in trouble. If you do hit that limit I think saving the form under a separate name should reset the counter.
Note you can use the following construct to refer to controls and make life easier.
Me.Controls("abc" & Row & column)
For example in the After Update of the type control you could use
call InsertRecords(3, "B")
sub InsertRecords(row as integer, Column as string)
....
cboTypeValue = Me.Controls("cboTypeID" & Row & Column)
....
This could be used as some kind of native access controls only grid.
If someone would post an example of how to create custom unbound subform with row for each unbound record and a code to loop and save it to the tables would be just great.
There wouldn't be as much controls and it wouldn't have any limits by the numbers of fields on form.

Filemaker: Best way to set a certain field in every related record

I have a FileMaker script which calculates a value. I have 1 record from table A from which a relation points to n records of table B. What is the best way to set B::Field to this value for each of these n related records?
Doing Set Field [B::Field; $Value] will only set the value of the first of the n related records. What works however is the following:
Go to Related Record [Show only related records; From table: "B"; Using layout: "B_layout" (B)]
Loop
Set Field [B::Field; $Value]
Go To Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout [original layout]
Is there a better way to accomplish this? I dislike the fact that in order to set some value (model) programmatically (controller), I have to create a layout (view) and switch to it, even though the user is not supposed to notice anything like a changing view.
FileMaker always was primarily an end-user tool, so all its scripts are more like macros that repeat user actions. It nowhere near as flexible as programmer-oriented environments. To go to another layout is, actually, a standard method to manipulate related values. You would have to do this anyway if you, say, want to duplicate a related record or print a report.
So:
Your script is quite good, except that you can use the Replace Field Contents script step. Also add Freeze Window script step in the beginning; it will prevent the screen from updating.
If you have a portal to the related table, you may loop over portal rows.
FileMaker plug-in API can execute SQL and there are some plug-ins that expose this functionality. So if you really want, this is also an option.
I myself would prefer the first variant.
Loop through a Portal of Related Records
Looping through a portal that has the related records and setting the field has a couple of advantages over either Replace or Go To Record, Set Field Loop.
You don't have to leave the layout. The portal can be hidden or place off screen if it isn't already on the layout.
You can do it transactionally. IE you can make sure that either all the records get edited or none of them do. This is important since in a multi-user networked solution, records may not always be editable. Neither replace or looping through the records without a portal is transaction safe.
Here is some info on FileMaker transactions.
You can loop through a portal using Go To Portal Row. Like so:
Go To Portal Row [First]
Loop
Set Field [B::Field; $Value]
Go To Portal Row [Next; Exit after last]
End Loop
It depends on what you're using the value for. If you need to hard wire a certain field, then it doesn't sound like you've got a very normalised data structure. The simplest way would be a calculation in TableB instead of a stored field, or if this is something that is stored, could it be a lookup field instead that is set on record creation?
What is the field in TableB being used for and how?