I have a userform in which the user has entered text.
The user then enters a data click on the Microstation screen (which removes the focus from the form).
After the VBA program completes a task, I want the form to become active again, and display the insertion point where it was last (in the text box). I don't seem to be able to do this.
The form itself doesn't seem to have an Activate or SetFocus method. When I tried to use the .SetFocus method of the text box, the form doesn't become active, and the textbox doesn't display the insertion point anymore.
Can anyone help?
Is the form modal or non-modal? In the non-modal case the form can stay on the screen. In the modal case you probably need to just show the form again.
mark anderson [Bentley]
Visit me at https://communities.bentley.com/communities/other_communities/bentley_innovation/default.aspx
It's non-modal (property showmodal = false). The form stays on the screen.
Graham said:After the VBA program completes a task, I want the form to become active again
I'm guessing here because you want us to imagine what your code looks like. Presumably the task and form are part of the same VBA project?
How does a 'data click on the MicroStation screen' transfer text from your form to whatever happens next? What happens in that task? What happens when the task is complete?
Regards, Jon Summers LA Solutions
Jon Summers said:the task and form are part of the same VBA project?
Jon Summers said:How does a 'data click on the MicroStation screen' transfer text from your form to whatever happens next?
The task is to produce an easting-northing co-ordinate table from Temporary Bench Marks (TBMs) in 2D. The user form allows additional information to be used to enhance the table, like Level (height) how many decimal places to format to, description etc.
The code gets the co-ordinates of the data click, then adds Label, Easting, Northing, Level & Description to a table.
After each data click, and hence a row in the table filled out, the user needs to type in a new TBM Label (if it's not an automatically assigned one). So I want the TBM Label text box to have the text insertion point ready to type.
Here's the piece of code where I try to set the focus back to the form and control. The form is called frmTBMSchedule, and the control is called tbTBMLabel.
With frmTBMSchedule 'Set the focus to a form control ready for data input - if it's enabled. *** THIS IS NOT WORKING AT THE MOMENT. *** If .chkTBMLabel Then 'The checkbox is ticked, which implies the Label is enabled. If not, an error would occur. .tbTBMLabel.SelStart = 0 .tbTBMLabel.SelLength = Len(.tbTBMLabel) .tbTBMLabel.SetFocus ElseIf .chkRL Then .tbRL.SetFocus 'Set Focus to another control if the tbTBMLabel control is not enabled ElseIf .chkType Then .tbType.SetFocus 'Set Focus to another control if the tbRL control is not enabled End If End With
It's not clear why you can't focus on your UserForm. It's possible that you're attempting to reference a variable that creates inadvertently a copy of the form and you're setting focus to that copy (which you can't see because you have not shown it).
I've attached a VBA project that illustrates communication between a UserForm and a Locate Class. Copy the project to a location where MicroStation can see it. Keyin
vba run [UserFormCommunication].modMain.Main
modMain.Main pops a UserForm. A button on the UserForm starts the locator class and passes it a reference to itself. When you identify a text element, the locator class copies its text into a text box on the UserForm.