Consulting

Results 1 to 4 of 4

Thread: Migrating from VBA 6.x to 7.0

  1. #1

    Migrating from VBA 6.x to 7.0

    Hi there,

    I have a rather comprehensive VBA project that generates a bucklet load of documents for my work.

    As a feature, I have enabled a 'save work' mechanism, that works perfectly on VBA versions below 6.5 (6.5 and 7 causes errors).

    The code is below
    [vba]Open DocName For Output As FH
    For Each PG In UserForm1.MultiPage1.Pages
    For Each TB In PG.Controls
    If TypeName(TB) = "TextBox" Then Print #FH, TB.Name & ":" & TB.TEXT
    If TypeName(TB) = "CheckBox" Then Print #FH, TB.Name & ":" & TB.Value
    If TypeName(TB) = "OptionButton" Then Print #FH, TB.Name & ":" & TB.Value
    If TypeName(TB) = "ToggleButton" Then Print #FH, TB.Name & ":" & TB.Value
    If TypeName(TB) = "ComboBox" Then Print #FH, TB.Name & ":" & TB.TEXT
    Next TB
    Next PG[/vba]
    The problem is the line 'for each tb in pg.controls' fails with a 'method or data member not found error'.

    If there is a fix for word 2010 for this, or if anyone can suggest an alternative method for saving work in progress from a VBA word project, I be very grateful.

    Thanks
    Ian
    Last edited by Aussiebear; 08-20-2011 at 10:12 PM. Reason: Applied VBA tags to code

  2. #2
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Do you have PG explicitly dimensioned, or are you letting Word do that for you?
    But the short answer to your question is: no, microsoft didn't remove the .Controls collection from the MSForms.Page object in Word 2010.

    However, there are more "Page" classes than just the MSForms one, and so the newer version may be getting confused because it has more options than prior versions.

    Do you have:
    Dim PG As MSForms.Page
    or just
    Dim PG As Page
    ?

    Try setting it explicitly. And if you do not use Option Explicit in your code, you should start doing so.

    As for the other question-- I'm not quite sure what you're trying to accomplish with the above code. Not to be snarky... but the way I save my work in progress while coding a VBA Word project is to simply hit the Save button

  3. #3
    Hi Frosty,

    BIG THANKS, while I had been explicit (so to speak) I hadn't qualified it further with the 'msforms'.

    Solved my problem completely :-)

    LoL to the snarky, maybe I didn't explain myself very well. The function of that routine is to export all entries in the 30+ userforms to a text file, that can later be retrieved at a later to continue working on.

    So it's a 'save work' or 'Work in progress' function for the user, not the programmer.

    Thanks again, you saved my butt.


    Cheers
    Kes

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Sure thing. And as for the Save Input In Progress type function: got it.

    There are a lot of ways to do that, but if you've already got an established system, easy enough to stick with that.

    Just as an FYI, you can use SystemProfileString to store that kind of info in an .ini file (which you can organize by keys and sub values), or there are various ways to store stuff in the registry (CURRENT_USER hive mostly, or you run into permissions issues in a corporate environment), but if what you're doing works already, no need to break it. It really depends on whether you want stuff to follow the user around in a roaming profile kind of way... as well as what happens when multiple people use the same machine, etc.

    So many different scenarios-- but some of the more established functions take care of the kinds of things like whether or not your keyname/value pair already exists, as well as allow you to organize it a bit more by having sub keys (maybe based on the document you're creating), etc. Just pairing an object name and its value may or may not be as flexible as you might like.

    Of course, any time you ask a question like "are there other ways to do this?" in a programming community, you're likely to get a number of different answers... many of which will be correct, but maybe not right... for you.

    Personally, I've just written some code to organize my firm data into a couple of classes and sub classes (infoFirm, infoUser, infoOffice), sucking the data into the class from a SQL server (if online) or an XML file (if offline)... with the ability to update the XML file. This is an update to code which utilized UDTs and .ini files heavily as ways of organizing/storing/retrieving info.

    There are, of course, a lot of ways to organize information. The best way is the way which is most flexible to being adjusted with whatever frequency is needed in your environment

    How's that for a short answer?

    Cheers back!

    - Jason

Posting Permissions

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