N
natanz
I have been working with a document template, for which i am setting up
a userform to collect some info, that will then be put into the new
document.
here is the code i have so far:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim noOfRecords As Integer
'open the database
Set db = OpenDatabase("K:\source\projectlist.xls", False, False,
"excel 8.0")
'retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `Projnumbers`")
Set rs2 = db.OpenRecordset("SELECT * FROM `Projnames`")
'determine the number or retrieved records
With rs
.MoveLast
noOfRecords = .RecordCount
.MoveFirst
End With
' With rs2
' .MoveLast
' noOfRecords = .RecordCount
' .MoveFirst
' End With
'set the number of columns = number of fields in the recordset
'ListBox1.ColumnCount = rs.Fields.Count
'load the listbox with the retrieved records
ListBox1.Column = rs.GetRows(noOfRecords)
ListBox2.Column = rs2.GetRows(noOfRecords)
'cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set rs2 = Nothing
End Sub
as you can see it is connecting to an excel file and filling two
comboboxes with named ranges in the excel file. For reasons beyond my
control, at least for now, it would be better to connect to a TXT file,
or a CSV file. But those files don't have any provisions for named
ranges, at least not that i know of. Any help is appreciated.
a userform to collect some info, that will then be put into the new
document.
here is the code i have so far:
Private Sub UserForm_Initialize()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim noOfRecords As Integer
'open the database
Set db = OpenDatabase("K:\source\projectlist.xls", False, False,
"excel 8.0")
'retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM `Projnumbers`")
Set rs2 = db.OpenRecordset("SELECT * FROM `Projnames`")
'determine the number or retrieved records
With rs
.MoveLast
noOfRecords = .RecordCount
.MoveFirst
End With
' With rs2
' .MoveLast
' noOfRecords = .RecordCount
' .MoveFirst
' End With
'set the number of columns = number of fields in the recordset
'ListBox1.ColumnCount = rs.Fields.Count
'load the listbox with the retrieved records
ListBox1.Column = rs.GetRows(noOfRecords)
ListBox2.Column = rs2.GetRows(noOfRecords)
'cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set rs2 = Nothing
End Sub
as you can see it is connecting to an excel file and filling two
comboboxes with named ranges in the excel file. For reasons beyond my
control, at least for now, it would be better to connect to a TXT file,
or a CSV file. But those files don't have any provisions for named
ranges, at least not that i know of. Any help is appreciated.