I'm having trouble with loading records from a data file to an Access form list box.
I want to create a form that a user can view all records from a "students.dat" file via a list box that I created with 3 fields: StudentIdNo, FName, LName.
I'm also trying to use error handling. I've been at this for some time and cannot get it to work. Any help is deeply appreciated. Here's my code so far:
Code:
Option Compare Database
Option Explicit
Public Sub Form_Load()
On Error GoTo ErrorHandler:
StartHere:
'create Students data file
Open "C:\Program Files\Students.dat" For Output As #1
Exit Sub
ErrorHandler:
Dim liResponse As Integer
Dim lsStudentsIdNo As String
Dim lsFName As String
Dim lsLName As String
Write #1, "814-1234", "Carol", "Smith"
Write #1, "412-5678", "Mary", "Jones"
Close #1
Select Case Err.Number
Case 53
'File not found
liResponse = MsgBox("File not found!", _
vbRetryCancel, "Error!")
If liResponse = 4 Then 'retry
Resume StartHere:
Else
cmdQuit_Click
End If
Case 71
'Disk not ready
liResponse = MsgBox("Disk not ready!", _
vbRetryCancel, "Error!")
If liResponse = 4 Then 'retry
Resume StartHere:
Else
cmdQuit_Click
End If
Case 76
'Disk not ready
liResponse = MsgBox("Path not found!", _
vbRetryCancel, "Error!")
If liResponse = 4 Then 'retry
Resume StartHere:
Else
cmdQuit_Click
End If
Case Else
MsgBox "Error in program!", , "Error"
cmdQuit_Click
End Select
End Sub