PDA

View Full Version : Userform Reference Issue



pdl1028
04-27-2007, 07:00 AM
This is my first post so I will try and provide sufficient details and files to address my problem. I have multiple userforms that complete documents in MS Word. They are working fine, but they are all stored in the Normal.dot file. My Normal.dot file is huge and I need to reduce it's size. I have moved the userforms to a template that is used for the document, but I receive an error that an "object is required". I have tried various ways to reference the userform, but all give the same error. How do I reference the userform in the loaded template so execution can continue?

The attached forms are sample files. The file StartTest.Show is in the Auto Exec sub routine and starts things off. The templates are located in a template storage folder on a server.

Thanks for any help I can receive.

mdmackillop
04-27-2007, 08:32 AM
Normal is not the best place to store Word macros. It's the file most likely to become corrupted and is usually replaced when you encounter Word problems.
Create a new template say "Macros.dot" and save it in your Word Startup folder. This means that the macros are available to use as you do at present. If you need to edit them, you need to open the Template file, but you can always add a macro to do this simple task!

pdl1028
04-27-2007, 12:32 PM
Moved my userforms / macros to macros.dot in the startup folder as mdmackillop suggested. Still getting the same error - run-time error '424': Object required. What am I missing?

fumei
04-27-2007, 08:23 PM
Aaaackkkk!

My hackles get up whenever I see things like:

Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Sincerely,"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Lange & Company"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeParagraph

Bleeech, bleeech. Try to avoid this use of Selection. Or if you have to (and you don't) use one instruction instead of five. Instead of FIVE TypeParagraphs, you can use one instruction.

Selection.TypeText Text:= vbCrLf & vbCrLf & _
vbCrlf & vbCrLf & vbCrLf

OK, on to the main point. I am trying to find a initial userform.show instruction. Where is it?

You certainly get a Object required error on clicking Cancel on the Letter.dot userform (LetterTest1). As well you should.
Private Sub Cancel_Click()
LetterTest1.Hide
StartTest.Show

End SubThat's nice. There IS no StartTest userform.

...an object...is...required...to...show.

Yes, you do have a StartTest.frm file. How nice. Unfortunately, your project knows absolutely nothing about that file.

Right click the Project, Import file. Bring in StartTest.frm...and voila...the object required is now available.

BTW: ah, don't you think that the StartTest userform is, ummmm, rather large and empty looking??

fishy73
04-27-2007, 11:36 PM
Hi,

I'm trying to achieve something very silimar to what you have done, but I DO NOT WANT TO GIVE PEOPLE THE CHECK BOX option.

I would like to have the FILE NAME reference tow or more of the FILL IN BOXES in the user form, but I'm not 100% how to go about doing this.:think:

do you think you can give me a few tips?

thank You

regards

Ian :thumb

fumei
04-28-2007, 06:09 AM
Huh? What? Sorry, but what the heck are you talking about?

Please describe slowly, carefully.

WHAT have I done that you want to do similar to? If it is something in the file that was posted...don't you think it would be helpful to mention that?

WHAT Checkbox option?

WHAT "fill in boxes" re you talking about?

You post leaves a bit to be desired. Please think, and try again.

fishy73
04-29-2007, 05:20 PM
Hi Gerry,

sorry for the confusion. Let me see if i can explain it a little better.

The attachment above (FormTest.zip) has some forms in it (Letter + Fax).

If you open the LETTER.dot (& then alt+F11 & F5) a FORM MENU pop up with some blank boxes which you can fill up either by using the pull-down menu or by filling in the blank spaces

eg: Sender, Recipient, Company, Address, City, Subject, Dear

What I am trying to achieve is basically is to use to info in these boxes to create a MAIN REFERENCE TEXT LINE within the word document & use this name as the file name for the document, for example:

Sender - Date - Format - Company - Subject

so if for example the sender is YOU & we use today date & the format (Fax) with some auto numbering system, the company is microsoft & the subject is "latest service pack for winXP", it would read something like this:

Gerry - 20070430 - Fax 0001 - MICROSOFT - "Latest Service Pack for WinXP.doc

The date will have to be include as part of the form or include it in some VBA code.

I got the FORM READY with all the code but how to extract the info from the form to create the reference & then the file name is where I'm stuck.

can you give me some tips please?

cheers

Ian

fumei
04-30-2007, 08:02 AM
Excuse me...but do you have two usernames here?

The original poster is pdl1028.

You are fishy73, yet you are talking as if the attached document (from pdl1028) is yours. Before we go any further, please clarify.

pdl1028
04-30-2007, 08:05 AM
Gerry -

I apologize for the poor coding and will try to correct in the future. Yes the form is large because it really has 13 options. I removed most options to simplify the problem.

Again, while you say "just load the form into the project", it doesn't work for me.:banghead: I will try again to explain what I am doing.

1) StartTest.show is in the AutoExec of the Normal.dot file.
2) LetterTest1.frm is in the Letter.dot template file.
3) User chooses the "Letter - New" option from the StartTest form which then loads the template Letter.dot and tries to continue with LetterTest1.Show.
4) An "Object required" error occurs.

So, the userform LetterTest1.frm is in TemplateProject(Letter), but not in Project(Document1). I import LetterTest1.frm into Project(Document1). Execution still does not continue with the same "Object required" error.

I know I am doing something stupid and can't seem to see what it is. Your help would be greatly appreciated.

Regards,

Paul

pdl1028
04-30-2007, 08:11 AM
Fishy73 is not my username but someone else looking for help.

Regards,

Paul (pdl1028)

fumei
04-30-2007, 09:08 AM
1) StartTest.show is in the AutoExec of the Normal.dot file.
2) LetterTest1.frm is in the Letter.dot template file.
3) User chooses the "Letter - New" option from the StartTest form which then loads the template Letter.dot and tries to continue with LetterTest1.Show.
4) An "Object required" error occurs.


1. That is a bad idea.
2. StartTest may load the template Letter.dot but IT (StartTest) is still the active form, and IT is in normal.dot and normal.dot does not have LetterTest1 form...ergo
3. IT (StartTest) does not have access to the LetterTest1.

StartTest has to explicitly call LetterTest1 from the template.

Look up the Run method in Help. Put a procedure to show the userform in the template, and run it.

fumei
04-30-2007, 09:10 AM
BTW: are you sure you want this in AutoExec? It will execute every time you use Word.

fumei
04-30-2007, 09:14 AM
fishy73 - I am a bit confused as to what you are asking.

Controls on a userform (textboxes, comboboxes) can put their values (text) into a document where ever you want. they are strings.

So take the text from the userform boxes and...put it in the document.

As for the filename, umm, take the strings in the document and use it as a filename.

As the attached files are NOT yours, perhaps it may be better if you start a new thread, clearly explaining what you want to do, and attach your own file.

pdl1028
05-14-2007, 12:06 PM
After I got my head out of the sand, all macros have been removed from the normal.dot and are working well in a macro.dot file. Thanks for your help.

mdmackillop
05-14-2007, 02:22 PM
You can mark your thread solved using the Thread Tools dropdown.