Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 7th, 2008, 06:19 PM
Registered User
 
Join Date: Apr 2008
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old April 8th, 2008, 09:24 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:41 PM.


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