View Full Version : Opening dialog box from form changes modal property
swamiandy
11-19-2006, 08:25 AM
Hello,
I have a user form which has a browse button that opens a file dialog box where the user can pick a folder. After control is returned to my form it has had its showmodal property changed to false! Is this a bug? Does anybody know how to change it back?
Kind Regards
Andy
lucas
11-19-2006, 10:09 AM
Can you post it Andy...I'm thinking this should not be too hard to fix but would be much easier to get to your solution if we could see it...
swamiandy
11-19-2006, 11:19 AM
sure...
it's a macro called "getform". You need to have some text selected for it to run (press Alt-Q to bring the form up)
Kind Regards
Andy
lucas
11-19-2006, 11:48 AM
Hi Andy,
I'm a little confused as your form is not "modal" before you browse!? Modal meaning you can click on the sheet and type while the form is open.....
I don't understand where your getting showmodal property either? Please give a little more info so I can understand the problem.
swamiandy
11-19-2006, 12:00 PM
sorry - maybe i got my terminology mixed up.
basically - i want the user to be unable to do anything else with the document until the form is closed. (That's how the form starts - but then after pressing the browse button the form changes so that you can access the document text)
i am setting the "ShowModal" property to true in the form design view
kind regards
Andy
lucas
11-19-2006, 04:12 PM
Hey Andy,
I can't seem to duplicate your error....I have renamed it to a .doc and I had to comment out the initialize code to get the form to run as there are files associated that I don't have...etc.
but if I run the form and browse to a directory, after the browse window closes I still can't access the word page while the form is open...?
I also can't find where you say your setting the ShowModal property to true in the userform properties??? I don't understand what you mean by design view unless you are talking about looking at the forms properties in the visual basic editor....
There is probably a language problem going on here so that I'm not completely understanding so be patient and we will try to figure this out.
swamiandy
11-20-2006, 01:05 AM
Hi Lucas,
You shouldn't need any extra files for the form to work. Just put the addin in the Word\Startup folder, then open another document, and then open the form by pressing Alt-Q (some text needs to be selected for it to open).
The purpose of the addin is to categorize transcriptions. In our organization we have 100s of transcribed audio recordings of people speaking on a variety of subjects (mainly in the form of Q&A sessions). In a single document many different topics may be addressed. I am building a database so that we can go through all the material and store it by subject category.
When the addin is loaded, the user can highlight some text in the active document and press Alt-Q to open the form. He then enters categorization information (via one combo box and one textbox). When he presses the submit button the information about the selected text is written out to an excel spreadsheet (startpos, endpos, wordcount...)
For each new word document a new spreadsheet is created, having the name docname_Meta.xls. (You specify the folder where these 'Meta" sheets are stored on the options tab - that's where the browse button comes in. Normally this will not need to be changed). Another spreadsheet called 'Categories_Meta.xls' is also used, which keeps track of all the category names that have been created so far (over all the documents), which is used to populate the combo box when the form is loaded.
I set the showModal property in the Visual Basic form editor when I was coding the addin.
When the addin is first used, you need to specify a location for the meta sheets to be stored (on the options tab), then when you hit submit the first time, the spreadsheets are automatically created.
Hope this clarifies
Kind Regards
Andy
p.s. I'm using Word 2002
lucas
11-20-2006, 07:59 AM
Ok.....got ya so far. I can't hit submit because I don't have the excel files to fill the comboboxes but it all works as expected otherwise. I just don't understand the modal/nonmodal part you can't click on the word page at any time while the form is open. Is that what you want?
My other observation about this:
you say:
I am building a database so we can go through all the material and store it by subject category.
Word is not a database program....as Gerry will tell you, its a Word Processor program. You should consider using Access or at least Excel for this task.
fumei
11-20-2006, 08:04 AM
Actually Andy, Steve was correct. Your earlier file DID require files.
OK, the new version seems to work sort of. Although if I open the saved file and try it again, I get a run-time error:
"Could set the Value property. Type mismatch"
However, as the template file is not open, there is no debug available. So I am not sure what is mismatched.
BTW: I do NOT like that you have Cat Tools on its own toolbar. I see no need for this.
Ok, this is fairly sophistuicated. Can you run by what the problem is again?
If it is just a focus issue getting the userform back as focus, this can be done simply.
File Dialogs are Application events. When a dialog is displayed focus is shifted to the Application. As the Application is top dog in the scheme of things, it retains the focus unless an explicit instruction is passed to shift focus. This can be done easily by:
userform.Hide
display dialog
userform.Show
By hiding the userform BEFORE calling the dialog, focus is explicitly changed from the userform. The dialog is called - which explicitly gives focus to the Application. the dialog closes and focus is explicitly given to the userform.
The userform must have a .Hide first, before you can .Show it again.
When you display any Application dialog from a userform, you should .Hide the userform immediately before the call to the dialog. Then you can .Show it after the dialog is closed. Focus will be explicitly given to the userform.
The userform modaility is not being changed. Code execution is returned to the userform when the dialog is closed, but focus is not. The Application will not release focus until explicitly told to do so.
I hope this helps. if not, please restate the issue.
BTW: pretty nice work here.
I notice however, that if you have input a category, and you pull the userform up again, there is no way to add details to an existing category. Or so it seems. You have to put in Details at the time of creating the category.
I am still trying to find the run-time error Type Mismatch.
swamiandy
01-02-2007, 01:14 AM
Hi Fumei,
Sorry for the long delay in replying. Thanks for the info. I've come quite a long way with the application now. There's just one final thing that I need help with.
I've decided to make the form non-modal. After using the app for some time, I found that it is more useful to be able to scroll through the document while adding categories to the form (if the selection spans several pages - I need to read through and add categories as I go through it).
However, now it is possible for the user to lose the selection (e.g. if he clicks anywhere in the document twice). Now, when he hits the submit button an empty selection is sent to the database.
Is there a way to disable the submit button if the selection length becomes < 3 characters? (I don't know which events I need to use. Whether I should look for a selection change event, or a form event that occurs immediately before I try to click on the submit button where I can check the selection length and disable/enable the button accordingly)
If you are interested I can attatch the template file. But now it connects to a mysql database which is the backend of a wordpress powered web site. (So it won't work unless you have the database connection setup)
Kind Regards
Andy
swamiandy
01-02-2007, 01:17 AM
BTW: the details correspond to the selected text - not the categories
Andy
fumei
01-02-2007, 06:27 AM
Is there a way to disable the submit button if the selection length becomes < 3 characters? (There is no need to disable the Submit button. This is a logic issue.
a form event that occurs immediately before I try to click on the submit button where I can check the selection length and disable/enable the button accordinglyAgain, it is a logic issue and can be built into the Submit button. There is no way you can find anything that will execute before you try to click the button. How would it know????? Just put some logic IN the Submit button.
Sub Submit_Click()
If Len(Selection.Text) > 3 Then
' do the stuff
Else ' selection is 3 or less
Msgbox "Selected text is too small for database."
' or something to inform the user
Exit Sub ' code terminates the button action
End If
End Sub
BTW: there is no Selection Change event in Word.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.