+ Reply to Thread
Results 1 to 25 of 25

UserForm Query

  1. #1
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    UserForm Query

    Before I waste anyone's time I'm going to ask a question, as I've already asked on another forum and I've been told to forget it...not in so many words.

    Basically I am trying to create a UserFrom in Word 2007 which involves a multipage tool and some textboxes...seemingly nothing too taxing.

    However I am having some problems, due to the fact that what I know about VBA you could fit in the corner of a postage stamp...

    I assume that there is some overlap between VBA for both Excel and Word? Y/N.

    If so would someone on here be prepared to give me a nudge in the right direction and put my mind at rest. I'm pretty much googled out and the Word forums don't seem anything like as "lively" as excel ones (inc. this one)

    This is pretty much my last attempt, or I'm going to put the book down and give it up as a bad job.

    Here's hoping

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,466

    Re: UserForm Query

    I think the Word Object Model is quite a bit different to the Excel Object Model.

    You really need examples of Word VBA code rather than attempt to translate Excel VBA.

    My opinion only and I may be wrong.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    Word's VBA and Excel's VBA share a common vba library (str, format, split, join, filter, sqr, cstr, strconv, copyfile, dir, filelen, name, chdir, etc.).
    However Excel and Word are very different programs, so they also have an VBA library of their own. E.g. An Excel file is a 'Workbook', A Word document is a 'Document', Excel has 'cells', Word has 'Paragraphs', etc. But if you are familiar with both libraries, it's very easy to let those libraries communicate.



  4. #4
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    That's fine. I welcome and value your opinion, afterall you know far more than I ever will. I think I'll go with "best of three" or something in terms of responses...

    1 nil to "let it go Louie"

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    And what is your question concerning queries & userforms ?

  6. #6
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Ooo, another post whilst I was replying...however sounds like 2 nil to "let it go Louie"....perhaps I was a bit premature with my best of 3, as I'm now resigned to locking myself in a dark room with an Enya **.

    BTW, sorry this thread is not exactly "informative". Moderators, please feel free to move or delete this thread as you see fit!

  7. #7
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    To SNB,

    At the risk of being chastised for cross-posting (as I have already stated I have asked this of "word specific" forums already and either have had no replies or had it suggested that I try something more in line with my capability...like switch my machine off...a little harsh I guess but a simple "no it can't be done" rather than "what do you want to do that for" would be easier to digest...

    Basically I am trying to create a UserForm that allows users to enter written text into various textboxes in response to specific questions. The UserForm is set up to closely matchthe format of a database into which the information will eventually be manually pasted. Why not just type the info directly into ther database I hear you ask?

    Good question...the reason is that the database automatically logs you out after a predetermined time if no activity is detected, therefore it is easy to loose your work, if for example, you need to take a toilet break...! Also once entries are submitted they are locked so that you cannot edit them in any way, only view them.

    Therefore users tend to paste an aide memoir from the database into word, type out their report, read/ amend it etc. as per the aide memoir, and then paste the completed article back into the database.

    What i'm trying to do is somewhat ****, yes, but in essence it should make the report creation a bit neater and more efficient.

    It has been suggested that I try Form/ Field controls instead...but ironically I cannot get the same level of conformity with them that I can with the UserFrom, given the smidgen of knowledge that I have.

    The specific questions I have at the moment are as follows...

    1. I can get a vertical scroll bar within a Multipage Tool which works when inputting data when the UserForm is "live", However I cannot get it to expand when in design mode, which is required to allow for the placement of numerous further TextBoxes, so that I don't have an OVERLY long UserFrom to start with.
    2.One of the textboxes is formatted for Sentence Case, but I also want to code it to automatically display MONTH and WEEKDAY names i.e. SATURDAY, JULY in capitals.
    4. Can a textbox be coded to allow for carriage returns, i.e. to produce paragraphs?
    5. Can a textbox be coded to spell check an entry when it is submitted prior to being displayed in the finished document (THIS IS NOT CRUCIAL - I'm jsut trying to be fancy!!)

    That's pretty much it at the moment.....apologies this is long-winded but I'm at the last chance saloon with this and, if the chap who has so far tried to put me off reads this he is likely to hunt me down and turn me into dog food.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    1. I can get a vertical scroll bar within a Multipage Tool which works when inputting data when the UserForm is "live", However I cannot get it to expand when in design mode, which is required to allow for the placement of numerous further TextBoxes, so that I don't have an OVERLY long UserFrom to start with.
    2.One of the textboxes is formatted for Sentence Case, but I also want to code it to automatically display MONTH and WEEKDAY names i.e. SATURDAY, JULY in capitals.
    4. Can a textbox be coded to allow for carriage returns, i.e. to produce paragraphs?
    5. Can a textbox be coded to spell check an entry when it is submitted prior to being displayed in the finished document (THIS IS NOT CRUCIAL - I'm jsut trying to be fancy!!)
    Ad 1. It's not necessary to switch to design mode; We can create as many textboxes we want, we can show them (visible/unvisible) based on the user's input. No we never design real-time when the user uses the form (and we don't need to)

    Ad 2. No problem, we can do that real-time (using the 'change' event), or afterwards before writing to a sheet/document/database.

    Ad 3 (4). A texbox can be .multiline =true ; .enterbehavior=true

    Ad 4 (5) Why would you if Word has a spellchecker of it's own ? We can show the result to the user. We need his/her interaction to check the spellchecker.

  9. #9
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    SNB, you may just have made my flippin' day!

    In answer to your last post...as per the points raised...

    1. I think I have mislead you with an insufficent description of what I'm on about...

    On the Multipage tool I will be setting up 6 pages. Each page will contain approximately 6-7 textboxes, each with a height equal to approx. 84 (for ease of reviewing what is being written, as it can be quite lengthy). I have designed the UserFrom to be a certain height and width, to keep it relatively neat, however this of course means that not all of the textboxes can be displayed without scrolling vertically.

    Whilst when the UserForm is "live" for data entry the scroll bars are visible and work fine, I cannot add the required number of textboxes when designing the UserFrom without altering the height of the UserFrom (i.e. it wont scroll vertically), which would mean that the UserForm would be too long for the screen...hope this makes more sense!

    2. Not exactly sure what a "change event" is other than logically understanding the concept. I think I have encountered one of these in setting up the text box to a) automatically change the text to Uppercase when entered, and b) automatically changing the text to Sentence Case when entered.

    I think I understand the concept of what I want to code but don't know how to write it, i.e. specifying that when a particular word is encountered it automatically changes it to Upper Case.

    3. This is excatly what I wanted, now works a treat...thanks

    4. I quite agree....Once it dumps the info into the document I'll just run the spell checker.

    I also have a cunning plan regarding your point about making textboxes visible/ invisible based on user input...if I understand what you mean...but I'll expand on that later if that's ok with you...I just want to get the thing running for now.

    Lastly....THANK YOU!

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    I you have further questione, please post a sample workbook. Much easier talking...

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: UserForm Query

    FYI, moved to Word Programming as it's not Excel related in any way.
    Remember what the dormouse said
    Feed your head

  12. #12
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Thank you...

    Hopefully it should be attached. The last chap kept telling me there was nothing there....but then the last chap said none of this could be done.
    Attached Files Attached Files

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    Can you please post it as a dot or doc file ?

  14. #14
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    For some reason it wont allow me to attach a .dot file. I have sent through a zipped dot.. see if that works...if not I will send through some jpegs which give you an idea of what i'm doing....
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    JPEGs if the latter didn't work...
    Attached Images Attached Images

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    cfr the attachment, without bookmarks but with documentvariables.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Thanks for the attachment...I'm currently pawing over it...trying to understand it.

    I'm guessing that you maybe created the userform from scratch from the images, either that or the one in the .dot file was so long winded...

    Anyhow the output is a little different from mine so I'm having a play with it.

  18. #18
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Can I ask you a couple of questions (basivally as this is all new to me)...

    1. What is the significance of using "J" as the variable name.
    2. What is the significance of the Tag statement, and why have spaces between some of the "" and other don't.
    3. What within the code allows for the format (spaces) between each of the text lines?

    Cheers,

    Andy

  19. #19
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Sorry...vbCr creates the carriage returns...got that bit.

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    1. systematic programming habit: first loop 'for j=1 to' , first nested loop 'for jj=1 to', second nested loop 'for jjj =1 to' , etc.
    2. tag="" perform the event, tag=" " do not perform the event. It's an alternative for application.enableevents = false, that doesn't work in a userform. This method is necessary to prevent endless loops.

  21. #21
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Thank you for all your help so far...

    I need to put in a combobox prior to one of the question textboxes, with some predetermined responses, code below...

    How do I set the textbox to display what is selected in the combobox if no entry is made in the textbox itself. I also have a default text line for the combobox but with the method I have used it automatically displays in the textbox, unless an alternative selection is made.

    If no selection is made in the textbox, I need the textbox to dislay what has been typed in it.


    PHP Code: 
    Private Sub UserForm_Initialize()
    ComboBox1.AddItem "test answer 1"
    ComboBox1.AddItem "test answer 2"

    If TextBox4.Text "" Then
    TextBox4
    .Text ComboBox1
    Else
    TextBox4.Text TextBox4

    End 
    If

    End Sub 
    Cheers,

    Andy

  22. #22
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    Pleas, use the correct code tags !!

    Never use additem to populate a combobox/listbox but use '.List'

    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Sorry about the tags, and again thank you for you help.

    I'm nearly done with thisnow, I just have a few more questions, shown below...I have also attached the updated file.

    1. Can the date textbox be replaced with some sort of date picker, rather than having to manually type in a date. It needs to be formatted to “ddMMMyy” when submitted.

    2. What can I replace combobox1 with in order to make multiple selections, which would be displayed in the document as “PERSON #, PERSON #, PERSON #...etc” on pressing of the submit button.

    3. The main ‘free-text’ textboxes e.g. textbox4 will be formatted in the same way i.e. Sentence Case. How can I specify that any DAY or MONTH names are displayed in UPPERCASE in the document when submitted.

    4. At the moment, if the user starts keying in text into textbox4 and then deletes it to begin again it causes a run time error. Why is that?

    5. When the submit button is pressed the text is copied into the word document but it does not start on the first line?

    6. It also creates a word document with a line spacing of 1.15, with 10pt space after each line. How do I change that to 1.0?

    7. To make things easier I have elected to display anything selected in one of the ‘Question’ comboboxes on a separate line from any ‘Question’ textbox entries. However, even if nothing is typed into the textbox it still leaves a blank line in the word document. How do I stop that?

    8. How do I make the headings appear in BOLD in the word document?
    Attached Files Attached Files

  24. #24
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: UserForm Query

    Can anyone help with this....?

  25. #25
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: UserForm Query

    1. Can the date textbox be replaced with some sort of date picker, rather than having to manually type in a date. It needs to be formatted to “ddMMMyy” when submitted.


    You can use a combobox, filled with dates:

    Please Login or Register  to view this content.

    2. What can I replace combobox1 with in order to make multiple selections, which would be displayed in the document as “PERSON #, PERSON #, PERSON #...etc” on pressing of the submit button.

    You can only use multiple selections using a Listbox

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1