C
cyberdude
Hi,
I load a range of data into a listbox from a named ranged in an excel
spreadsheet by modifying the code in this link:
http://word.mvps.org/FAQs/InterDev/XLToWordWithDAO.htm
So, my modified code is:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim object_name(50), object_chinese_name(50) As String
Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `myDatabase`")
i = 0
While Not rs.EOF
object_name(i) = rs.Fields(0).Value
object_chinese_name(i) = rs.Fields(1).Value
ListBox1.AddItem (object_name(i))
rs.MoveNext
Wend
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
I invoke the userform by the following simple code:
Sub show_form()
UserForm1.Show False
End Sub
Sometimes, I hide the userform by the code
Sub hide_form()
UserForm1.hide
End Sub
I would like to know if I repeatedly hide the userform by Sub
hide_form() and then invoke the userform by sub show_form(), will it
run the UserForm_initialize() and load the data from Excel again and
again? If it does, it will use more and more computer memory to hold
the data. Can the re-loading of data be avoided?
Mike
I load a range of data into a listbox from a named ranged in an excel
spreadsheet by modifying the code in this link:
http://word.mvps.org/FAQs/InterDev/XLToWordWithDAO.htm
So, my modified code is:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim object_name(50), object_chinese_name(50) As String
Set db = OpenDatabase("C:\Test\Book1.xls", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `myDatabase`")
i = 0
While Not rs.EOF
object_name(i) = rs.Fields(0).Value
object_chinese_name(i) = rs.Fields(1).Value
ListBox1.AddItem (object_name(i))
rs.MoveNext
Wend
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
I invoke the userform by the following simple code:
Sub show_form()
UserForm1.Show False
End Sub
Sometimes, I hide the userform by the code
Sub hide_form()
UserForm1.hide
End Sub
I would like to know if I repeatedly hide the userform by Sub
hide_form() and then invoke the userform by sub show_form(), will it
run the UserForm_initialize() and load the data from Excel again and
again? If it does, it will use more and more computer memory to hold
the data. Can the re-loading of data be avoided?
Mike