Userforms - update view whit userform still active

Userforms - update view whit userform still active

stefanveurink68AXD
Advocate Advocate
1,757 Views
8 Replies
Message 1 of 9

Userforms - update view whit userform still active

stefanveurink68AXD
Advocate
Advocate
Dear experts, At first, i wonder when i got a userform active, and do some macro by clicking a button, how to update the view without ending the userform. in other words, when i click the button the macro runs well but because the userform stays active, i can't see the results until ending the userform, how to prevent this? Next to that i also wonder why when i give a button a certain text, and then with the userform active i click the button, after that the buttontext is set back to something like ' CommPrivate Sub Userform_Activate()' and some of the code. how to prevent this? Thanks!
0 Likes
1,758 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

As for your first question, its a little hard to be sure of what you're asking, but perhaps Norman's third answer in this thread will answer your question.

 

As to your second question, you can't expect much help with errors if you don't show your code so we can see what you might be doing wrong. It may be that you added code to your button event and then renamed the button. VBA won't rename the event for you. You need to rename the code signature too. For example, if you had a button named "CommandButton1" and modified the Click event to the following:

Private Sub CommandButton1_Click()
    MsgBox "This is a test"
End Sub

Then you changed the Name property to "cmdTest", the previous CommandButton1_Click() method will be orphaned and a cmdTest_Click() method will be created. You need to manually edit the previous method's name in the code module or move the code from that method to the newly created method.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 9

stefanveurink68AXD
Advocate
Advocate
About the answer to the second question, the commandbutton, thanks, I think i see the problem and it doesn't happen anymore now. About the answer to the first question, by setting property "showmodal" to false I got what i want so thanks again. Only question left is why, in the answer you refer to, there's strongly advise to not use this option. what is the problem with it?
0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor
That was Norman's opinion, maybe @norman.yuan can answer that question.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

stefanveurink68AXD
Advocate
Advocate

Guess i've found out why....

 

Seems like when i put property "Show modal" to false, indeed it updates the view and stuff and allows you to edit drawing with userform still open.... 

 

On the otherside... I can't fill in the textboxes of the userform anymore. quiet necessary right? so this ain't a solution. 

 

Anyways I would still like to update the view after certain buttons/macro's on the form because if not, this surely is gonna give problems and mistakes. For example the version..... when i can't see the version has allready been updated you might click the versionbutton (a few times) again... making you versionnumber going sky high.

 

Is there anyway to at least update the view after a macro with userform still active??? The best would be if you could also work in the drawing when the userform is opened, but at least updating the view is a must. Any options?

0 Likes
Message 6 of 9

norman.yuan
Mentor
Mentor

Using UserForm as modeless form (float form) to only show information without the need of user interaction is fine. BUt in most cases in AutoCAD, you would need some sort of user interaction. So, you need to add an AcFocus control to the form in order for the form to be able to stay focused. It is a very strange way to do things (that is why I said that I do not recommend it in previous reply). Also, when the form is floating, you must realize that user can which active drawing from one to other. If the floating form showing data related to one drawing, when the active drawing changes, you must either somehow automatically update the form's data, or close the form, so use is not confused to face a drawing and see data on the form for different drawing...

 

When displaying form as Modal dialog, you CAN STILL UPDATE AutoCAD view for reflect the change you made to the entities in the drawing, or update the current view (zoom/pan...).

 

I wrote following code for a small UserForm to show how to update an AcadText entity is updated in AutoCAD via a dialog box:

 

Option Explicit

Private entText As AcadText

Private Sub cmdPick_Click()
    
    Me.Hide
    
    Set entText = PickTextEntity
    
    If Not entText Is Nothing Then
        cmdUpdate.Enabled = True
        txtText.Text = entText.TextString
    Else
        cmdUpdate.Enabled = False
    End If
    
    Me.show
    
End Sub

Private Sub cmdUpdate_Click()
    If Len(Trim(txtText.Text)) = 0 Then
        MsgBox "Text value is required!"
        Exit Sub
    End If
    
    If Not entText Is Nothing Then
        entText.TextString = Trim(txtText.Text)
        entText.Update
    End If
    
End Sub

Private Function PickTextEntity() As AcadText

    Dim ent As AcadEntity
    Dim pt As Variant
    
    On Error Resume Next
    
    ThisDrawing.Utility.GetEntity ent, pt, vbCr & "Pick a text entity:"
    If Not ent Is Nothing Then
        If TypeOf ent Is AcadText Then
            Set PickTextEntity = ent
            Exit Function
        End If
    End If
    
    Set PickTextEntity = Nothing
    
End Function

See the video clip below:

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 9

ferhatttcoskun
Enthusiast
Enthusiast

Let the text or mtext objects I select from the screen write to texbox1.text

write next selection to textbox2

write next selection to textbox3

write next selection to textbox4

 

If I click in an empty place, it will beep.

 

if I choose another object, msgbox"please select text or mtext object"

 

I want to do like this.
Can you help me, please?

Thank you.

0 Likes
Message 8 of 9

Ray-Sync
Advocate
Advocate

@norman.yuan Hello! I noticed that in your videos, there's an on-screen mouse cursor icon and keyboard key presses displayed. Could you please let me know what software or program you use to achieve this effect? I'm interested in using something similar for my own videos. Thank you!

jefferson
0 Likes
Message 9 of 9

norman.yuan
Mentor
Mentor

It was Autodesk's ScreenCast, which was free for login AutoCAD users, until Autodesk recently discontinued the support. So, you have to find your own screen capture app.

Norman Yuan

Drive CAD With Code

EESignature