Hi,
I have made some simple modifications to the export code which will prevent the application from displaying until the data has transferred. It should also execute faster as it is not updating the screen with each iteration.
Do you have students with multiple languages, or only 1?
I have made some simple modifications to the export code which will prevent the application from displaying until the data has transferred. It should also execute faster as it is not updating the screen with each iteration.
Do you have students with multiple languages, or only 1?
Code:
Private Sub cmdExport_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim rst As DAO.Recordset
Dim lngRow As Long
On Error GoTo ErrorcmdExport_Click
Set rst = Me.sfmStudentClasses.Form.RecordsetClone
If rst.EOF Then
MsgBox "No classes have been selected", vbInformation, "No Classes Selected"
Else
Set xlapp = New Excel.Application
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
' Get header names
' Do not export last field because this is an ID
For I = 0 To rst.Fields.Count - 2
xlsheet.Cells(1, I + 1).Value = rst.Fields(I).Name
Next
lngRow = 2
Do While Not rst.EOF
' Do not export last field because this is an ID
For I = 0 To rst.Fields.Count - 2
xlsheet.Cells(lngRow, I + 1).Value = rst.Fields(I).Value
Next
lngRow = lngRow + 1
rst.MoveNext
Loop
End If
ExitcmdExport_Click:
xlapp.Visible = True
xlapp.ScreenUpdating = True
Set xlsheet = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
Set rst = Nothing
Exit Sub
ErrorcmdExport_Click:
MsgBox "Error number: " & err.Number & vbCrLf & _
"Error description: " & err.Description
GoTo ExitcmdExport_Click
End Sub