简体   繁体   中英

Open multiple copies of word form?

I'm fair at Access vba but Word is a new dialect for me.

I work for a hospital that has an Electronic Medical Record (EMR). We need a specific format and structure for the Nurse's Clinical Progress Notes that can't be created and enforced in the EMR. I created a Word vba UserForm, "frmProgNote" attached to a document "ProgNote.doc". FrmProgNote" has textboxes that create the structure we need for documentation and there is a command button that when clicked sends the info from the form to bookmarks in ProgNote.doc and copies all text from the document, including the newly inserted text onto the clipboard. The user then pastes it into the EMR. This all works great (believe it or not) but now they want to have multiple copies of frmProgNote open at the same time so they can move between several patients at once.

I've worked on this for 2 days and just can't get it. I found I could not open multiple instances of Word and have the same form open in more than one. I copied the document and form so now have ProgNote1.doc with frmProgNote1 and ProgNote2.doc with frmProgNote2. I can get both to open BUT if I open frmProgNote1 then open frmProgNote2 the only data I can copy comes from frmProgNote2; the copy button doesn't copy anything from the first form. I can click on frm1 and get it to take new data but the copy button doesn't work anymore. Any suggestions? Thanks so much.

The following code gives the basis for creating a new instance of a UserForm .

Private frmNewInstance As Object

Private Sub CommandButton1_Click()
    Set frmNewInstance = UserForms.Add(Me.Name)
    frmNewInstance.Show
End Sub

Private Sub UserForm_Terminate()
    Set frmNewInstance = Nothing
End Sub

It is necessary to control the object-reference, setting it to Nothing when the form instance is closed.

Note that this process is not as robust or reliable as it would be in, for example, VB.NET or C#. In particular, it is more difficult to distinguish between the different instances of the form.

One approach to consider is to use the Tag property of the form:

    frmNewInstance.Tag = "OtherOne"
    frmNewInstance.Show

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM