Consulting

Results 1 to 11 of 11

Thread: Solved: Assigning values to bookmarks/fields

  1. #1
    Knowledge Base Approver
    Space Cadet
    VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    Solved: Assigning values to bookmarks/fields

    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;?
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  2. #2
    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

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    VBAX Regular
    Joined
    Aug 2004
    Location
    On a 100 acre hobby farm in beautiful west Quebec.
    Posts
    87
    Location
    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?
    Eric

    Experience is not what happens to a man; it is what a man does with what happens to him. ? Aldous Huxley

  5. #5
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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;?
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  7. #7
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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.

    [vba]
    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
    [/vba]
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  8. #8
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    problem solved - I really mustn't try to access tables cells that don't exist, musn't I .
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Also if your bookmark name is "WithVat" then it is not hidden. A hidden bookmarks would be "_WithVat".

  10. #10
    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

  11. #11
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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;?
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •