By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Copy listbox contents to another listbox

P: 1
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.ListBox1 in both documents and I can't seem to find a way to write doc.IRABene_Main.ListBox1and mean to update the blank form's listbox.

See the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub UpdateAdditionalAccount_Click()
  2. Dim appWord As Word.Application
  3.  
  4. Dim doc As Word.Document
  5.  
  6. Dim Name As String
  7. Dim SSN As String
  8. Dim bday As String
  9. Dim address As String
  10. Dim dayphone As String
  11. Dim branch As String
  12.  
  13. Name = Me.FormFields("name1").Result
  14. SSN = Me.FormFields("ssn").Result
  15. bday = Me.FormFields("bday").Result
  16. address = Me.FormFields("address").Result
  17. dayphone = Me.FormFields("dayphone").Result
  18. branch = Me.FormFields("branch").Result
  19.  
  20. Set appWord = CreateObject("Word.Application")
  21. appWord.Visible = True
  22.  
  23. Set doc = appWord.Documents.Add(Template:="S......Y.docm", NewTemplate:=False, DocumentType:=0)
  24.  
  25. doc.FormFields("name1").Result = Name
  26. doc.FormFields("ssn").Result = SSN
  27. doc.FormFields("bday").Result = bday
  28. doc.FormFields("address").Result = address
  29. doc.FormFields("dayphone").Result = dayphone
  30. doc.FormFields("branch").Result = branch
  31.  
  32. End Sub
Jun 23 '15 #1
Share this Question
Share on Google+
1 Reply


zmbd
Expert Mod 5K+
P: 5,397
+ 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.
Jun 23 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.