Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2008, 06:19 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populating a list box

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



 
Old April 8th, 2008, 09:24 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Took me all night, but figured this out on my own.

Thanks anyway. Have a great day.






Similar Threads
Thread Thread Starter Forum Replies Last Post
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
populating a list box using a DataReader goplayoutside VB Databases Basics 0 April 21st, 2004 07:27 PM
populating a drop down with a file list cjcd BOOK: Beginning ASP.NET 1.0 1 April 17th, 2004 02:53 AM
populating a box sporkman43 Classic ASP Basics 0 August 18th, 2003 02:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.