Copy listbox contents to another listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TByrd0716
    New Member
    • Jun 2015
    • 1

    Copy listbox contents to another listbox

    I have a form with a listbox. I want to open a new blank form and assign the same values to the blank form's listbox. What is the best way to go about doing this? I have a majority of the code configured. My problem is writing the proper syntax to assign the listbox in the new blank unsaved document "doc" the values from the first document's listbox.

    Should I declare a temporary listbox to carry over the values to the next listbox?

    My listbox is named IRABene_Main.Li stBox1 in both documents and I can't seem to find a way to write doc.IRABene_Mai n.ListBox1and mean to update the blank form's listbox.

    See the following code:

    Code:
    Private Sub UpdateAdditionalAccount_Click()
    Dim appWord As Word.Application
    
    Dim doc As Word.Document
    
    Dim Name As String
    Dim SSN As String
    Dim bday As String
    Dim address As String
    Dim dayphone As String
    Dim branch As String
    
    Name = Me.FormFields("name1").Result
    SSN = Me.FormFields("ssn").Result
    bday = Me.FormFields("bday").Result
    address = Me.FormFields("address").Result
    dayphone = Me.FormFields("dayphone").Result
    branch = Me.FormFields("branch").Result
    
    Set appWord = CreateObject("Word.Application")
    appWord.Visible = True
    
    Set doc = appWord.Documents.Add(Template:="S......Y.docm", NewTemplate:=False, DocumentType:=0)
    
    doc.FormFields("name1").Result = Name
    doc.FormFields("ssn").Result = SSN
    doc.FormFields("bday").Result = bday
    doc.FormFields("address").Result = address
    doc.FormFields("dayphone").Result = dayphone
    doc.FormFields("branch").Result = branch
    
    End Sub
    Last edited by zmbd; Jun 23 '15, 06:49 PM. Reason: [Z{Please use the [CODE/] button to format posted script and formatted text - Please read the FAQ}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    + Please confirm, this is in MS Word... not MS Access?

    + Also which version of Office/Word are you using?

    + We need to know the design of the listboxes too... multi-column? on a popup or a document (see the following)?

    + Form, we need to understand your "definition " of form. In word, people use the term "form" to refer to both the "dialog style" form that pops up an you place information into and the "document style" form where one opens a *.doc, *.docx, *.docm word document and there resides a template with fields that the user places entries into.

    The basic method will be to loop thru your current list box items and then use the additem method to refer to your form.
    Last edited by zmbd; Jun 23 '15, 07:01 PM.

    Comment

    Working...