Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Date format challenge (2000/SR-1)

    Date format seem to be a difficult matter for several people. Here is my difficulty:

    Using the code typed below, give me a date format that I do not want. It is neither the Word format for date or from the Regional settings. It seem to have its own. I would like to write a code that define the format within the code. Further this code is meant to insert the date the last time the template was saved. Thus giving this information on the filled in form(generated document) to show when it was last amended, working as a version number. As far as I have experienced the code works but gives me a date format that is not acceptable in our environment.

    The code line:

    Me.txtFormDate = ThisDocument.BuiltInDocumentProperties(wdPropertyT imeLastSaved)

    At the same time I have also made a code to insert the filename of the template in order to show this on the filled in form(generated document). This is working as well, but I should like to show only the file name except the extension of the file (.dot). The two information types then automatically shows the status of the template regardless of when the document generated from the template was made.

    Here is this code I hope to get some help to change in order to achieve my goal:

    Me.txtFormID = ThisDocument.BuiltInDocumentProperties(wdPropertyT emplate)

    The template itself is more than 100kb and thus cannot be attached here. If necessary it must be mailed.

    I very match appreciate help also in these cases. It will save a lot of time when amending templates and also secure that the template will be given a correct name and version(date).

    Regards

    Bj

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    Bjorn,
    To get the date into the format you require, you could use something like th efollowing : -

    Me.txtFormDate = Format(ThisDocument.BuiltInDocumentProperties(wdPr opertyTimeLastSaved), "dd/mm/yy").

    You can replace "dd/mm/yy" with your own preference.

    Andrew C

  3. #3
    New Lounger
    Join Date
    Sep 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    As for the template name try this:

    TempName = ThisDocument.AttachedTemplate.Name
    Me.txtFormID = Left(TempName, Len(TempName)-4)

  4. #4
    Lounger
    Join Date
    Jan 2001
    Location
    Milton Keynes, Buckinghamshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    Just to follow up on Darryl Hover's post (and what I am going to say may not be necessary or appropriate in this case), I am always wary of doing something like chopping the end off a string without being 100% sure of what I am throwing away. To satisfy myself that my code was only ever going to remove a ".dot" extension, I should use

    If Right(TempName, 4) = ".dot" Then
    Me.txtFormID = Left(TempName, Len(TempName)-4)
    Else
    Me.txtFormID = TempName
    End If

    in place of

    Me.txtFormID = Left(TempName, Len(TempName)-4)

    but I am probably being over-cautious (because of a massive lack of confidence in my coding ability).

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    I'd recommend

    <pre> If UCASE(Right(TempName, 4)) = ".DOT" Then
    </pre>




    Or better still:

    <pre> If UCASE(Right(tempname,len(strParam))) = ucase(strParam)
    </pre>


    where strParam is a string parameter to the function.

    Then there's the use of an optional boolean case-sensistive switch, but see also various <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=26609&page=&view= &sb=&o=&vc=1>discussions</A> on the use of optional parameters.

  6. #6
    Lounger
    Join Date
    Jan 2001
    Location
    Milton Keynes, Buckinghamshire, England
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    Chris,

    Thanks for these improved coding suggestions.

    I'm afraid you have left me behind when you refer to 'the use of an optional boolean case-sensistive switch'. In the current case, case sensitivity is probably not appropriate (which is one reason why your code is better than mine), but presumably your 'case-sensitive switch' could be used - in a more general case - to allow the user to specify whether or not case sensitivity was required?

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    >to allow the user to specify whether or not case sensitivity was required?

    Correct, he replied, nervously eyeing the VBA forum.

    In general a user GUI form would have a check-box that signalled "case-sensitive". The programmer obtains the setting and then applies that in the programming code.

    A utility function, such as a string-sort routine, ought to allow a switch that says whether or not the sort is to be case-sensitive. Such a switch is usually provided by the programmer as a parameter to a function call. The utility function (string sort) can declare that the parameter is optional - doesn't have to be supplied by the calling routine - in which case it has a default value.


    If I were using the sort utility as an adjunct to a user GUI, I'd take the user's option and pass it as a parameter to the sort utility.

    If I were using the sort utility internally (for example to sift through file extents) I might not provide the parameter, but let it default to case-insensitive.


    I hope this sheds some light. My response was mainly intended to caution against not considering Dot, dOt, doT etc when checking file extents.

  8. #8
    BAM
    Guest

    Re: Date format challenge (2000/SR-1)

    Why not use ActiveDocument.Type = wdTypeTemplate?

    This would include templates masquerading as *.doc's.

  9. #9
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Date format challenge (2000/SR-1)

    Hi and thanks very much to all of you contributing to my search for help!

    In my case I have found that the following will work:

    TemplateName = ThisDocument.AttachedTemplate.Name
    Systemp = Left(TemplateName, Len(TemplateName) - 4)

    UpdateTextBox Me.txtFormID, "bmFormID", Systemp
    UpdateTextBox Me.txtFormID, "bmFormID2",Systemp

    TemplateDate = Format(ThisDocument.AttachedTemplate.BuiltInDocume ntProperties(wdPropertyTimeLastSaved), "dd.mm.yyyy hh:mm")

    The following is also working:
    TemplateDate = Format(ThisDocument.BuiltInDocumentProperties(wdPr opertyTimeLastSaved), "dd.mm.yyyy hh:mm")


    UpdateTextBox Me.txtFormDate, "bmFormDate", TemplateDate
    UpdateTextBox Me.txtFormDate, "bmFormDate2", TemplateDate

    But, there is a great BUT, the first time I save the active document(produced with the template) I get two questions:

    1 SaveAs, a normal question in order to give the document a filename. This is as expected.

    2 Do you want to save the template? Even though the template( *.dot file) has not been changed! (or has it? if so what is changed??)

    If I change something in the established document, save it and close it I still get the question whether I want to save the template.

    What could cause this?

    PS
    I have understood that the term "ThisDocument" always refer to the template in use(or attached template). Using the code line: TemplateDate = Format(ThisDocument.BuiltInDocumentProperties(wdPr opertyTimeLastSaved), "dd.mm.yyyy hh:mm")
    should only refer to the template (mytemplate.dot) and therefore give the last saved date of the template. So why does it give me the question whether I want to save the template in use?

    I very much appreciate any answers and suggestions. Thanks!

    Best regards
    Bj

Posting Permissions

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