PDA

View Full Version : Solved: Assigning values to bookmarks/fields



sandam
03-24-2005, 09:52 AM
I'd like to know if its possible to assign a value to a bookmark or field but keep that object hidden from the user? Essentially it would be in a table but in cell that cannot be seen. I'd prefer to do it this was instead of using white text just from the styles point of view. The kind of values would be either true or false and some numeric values. I need them to be in the document so that i can access them if the user opens the document for editting.

Thanks In Advance

andrew;?

hairywhiterabbit
03-27-2005, 05:45 PM
Hi Sandam,

I'm not sure if it is possible to completely hide anything from a user if they are smart enough or really want to know, but if it is for a 'regular' user then you might be able to use a pretty crud hack with the sequential number field.

If you insert a sequential number field with a label that you can search for later ie 'myseqnumber' you can set the value of the number to anything you want. For true and false you can just 1 and 0 respectively. In you document find a place where you think the user won't toggle the field codes (you're buggered if they select all then toggle the field codes though) and put them there. Type Crtl+F9 to insert the field and then type SEQ UniqueName \r 6 \h. The \r resets the number to 6 (your value) and the \h hides the value from the user. To find the number you can toggle the codes in the document, search for UniqueName and move right to get the value. This method sux if you have a big document with lots of fields because it will take forever to update them all.

Another way you might consider is using the registry. VB actually has some builtin functions that you can use, GetSetting and SaveSetting, see the help file for all the useful info. You can access the registry when the document is openned. Of course, you'll need a seperate set of settings for each document...

Cheers,
Andrew

TonyJollans
04-02-2005, 02:42 PM
I'm not entirely sure what your objective is, but I would probably use document variables; they are entirely hidden from normal users. The difficulty might be in associating them with individual tables, or other individual document elements, if that is required, although you might be able to use hidden bookmarks to assist. If you give some more details of your requirement, somebody will come up with something suitable.

EricFletcher
04-03-2005, 08:26 AM
I concur with Tony; document variables are a safer way to maintain information that won't inadvertently be deleted by a user. Take a look at the File | Properties dialog, Custom tab. They have some pre-loaded options (Checked by, Client, stc.) but you can add your own. For example, for some jobs I use a custom variable "dsl" to specify the default spelling language I want used in the document. I can then display it's value with a field (via {DOCPROPERTY dsl }) or query it in a macro. You can also set it to be dependent on the content -- say the current value of a bookmarked cell in a table -- although of course, that would still be open to being deleted by the user. Does this help?

sandam
04-04-2005, 04:22 AM
I think i found my work around. I'm creating hidden bookmarks with meaningful names and then checking their existence ( a sort of boolean type). I'll post again when I've tested the theory.

Thanks again for the info.

Andrew;?

fumei
04-04-2005, 08:57 AM
Hidden bookmarks work well.

{DOCVARIABLES} work well too, although they can be funny sometimes.

As Tony mentioned, it would help if we knew exactly what your requirements are, precisely.

There is a third option. It depends of course on what you need. For example, what (and why) is the requirement for hiding it in the first place. Why do you need to hide it? It ceratinly is possible to LOCK things so the user can not change things. In any case, it is possible to put things into an ActiveX control and using conditional logic RESIZE the control. In other words, you can resize the control itself down to, say, 1 x 1 pixel. This is tiny and essentially invisible to the user. Unfortunately, they do not have a direct .Visible property. But they DO have a Width and Height. So you can hold - whatever, an image, some text, some data...whatever. And depending on your needs make it the size you want, or so tiny it disappears.

sandam
04-04-2005, 09:15 AM
I'm using the bookmarks to a) Set a range to search between in a table for specific calculations that cannot be done easily with fields and b) to determine parts of the calculation that will be lost if the document is exited - i.e for when the user returns to the doc to edit it.

I've gotten to this point and I get a requested member of the collection does not exist run time error. this is the specific point in the code where the error occurs. I think I might be adding the bookmark incorrectly?? but I'm not sure.


With ActiveDocument.Tables.Item(3)
If sWithvat = True Then
'this is the error line
.Cell(.Rows.count, .Columns.count).Range.Bookmarks.Add ("WithVat")
End If

sandam
04-05-2005, 01:51 AM
problem solved - I really mustn't try to access tables cells that don't exist, musn't I :).

fumei
04-08-2005, 12:56 PM
Also if your bookmark name is "WithVat" then it is not hidden. A hidden bookmarks would be "_WithVat".

hairywhiterabbit
05-01-2005, 09:58 AM
Hi Sandam and all,

I know you have solved your problem, but I came across this page and remembered your post so I thought you might be interested.

http://word.mvps.org/FAQs/TblsFldsFms/AddinFields.htm

Cheers,
Andrew

sandam
05-03-2005, 12:45 AM
Wow, I'd totally forgotten about this thread, and that link may prove to be very useful indeed. I'm also working with using excel spreadsheets as a way of storing values but its in a different context. Its almost like I'm using them instead of a database (because the one we use is in need of serious reorganisation :banghead). This link really helps alot, Thanks again
Andrew;?