Sub OpenText()
Dim Student as string,LName as string,FName as String,HClass as string,MyGrade as String,DateAsgn as String,Fac as String,MyLine as String
Dim MyRow as Long, recs as Long
recs = 0
MyRow = 1
'Read the Database Connection String
UpdateCon
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnstr = Conn
'Select the Records
strSql = "SELECT StudentNo,Last,First,Facility,MyClass,DateAsgn,Grade FROM Students WHERE Status = 'Assigned' ORDER BY StudentNo" '
cn.Open cnstr
rs.CursorLocation = adUseClient
rs.Open strSql, cn, , , adCmdText
If Not (rs.BOF = True) Or Not (rs.EOF = True) Then
rs.MoveFirst
While Not rs.EOF
Student = rs.Fields("StudentNo").value
' Open the selected file.
Open Filename For Input As #1
' Change the mouse pointer to an hourglass.
Screen.MousePointer = 11
Do While Not EOF(1) ' Check for end of file.
Line Input #1, MyLine ' Read line of data.
'Read the Data Needed
MyLine = Left(MyLine, 80)
If Left(MyLine, 6) = StudentNo Then
Student = StudentNo
'Break up the Data
LName = Mid(MyLine, 8, 23)
RTrim (LName) 'Trim any spaces
FName = Mid(MyLine, 31, 17)
RTrim (FName) 'Trim any spaces
HClass = Mid(MyLine, 48, 10)
RTrim (MyClass) 'Trim any spaces
Fac = Mid(MyLine, 59, 2)
Grade= Mid(MyLine, 65, 3)
DateAsgn = Mid(MyLine, 70, 10)
'Set the Coloumn Names
FrmDown.VSFlexGrid2.TextMatrix(0, 1) = "Student #"
FrmDown.VSFlexGrid2.TextMatrix(0, 2) = "Last Name"
FrmDown.VSFlexGrid2.TextMatrix(0, 3) = "First Name"
FrmDown.VSFlexGrid2.TextMatrix(0, 4) = "Facility"
FrmDown.VSFlexGrid2.TextMatrix(0, 5) = "Class"
FrmDown.VSFlexGrid2.TextMatrix(0, 6) = "Grade"
FrmDown.VSFlexGrid2.TextMatrix(0, 7) = "Assigned"
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = Student
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = LName
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = FName
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = Facility
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = HClass
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = Grade
FrmDown.VSFlexGrid2.TextMatrix(MyRow, 1) = DateAsgn
recs = recs + 1
MyRow = MyRow + 1
FrmDown.VSFlexGrid2.Rows = FrmDown.VSFlexGrid2.Rows + 1
End If
Loop
Close #1
rs.MoveNext
Wend
Screen.MousePointer = 0
FrmDown.VSFlexGrid2.Rows = FrmDown.VSFlexGrid2.Rows - 1 'Delete the Extra Row
End If
Set rs = Nothing
Set cn = Nothing
end Sub