-
Can't Open DB File
This snippet is supposed to open a db file for input. No matter how I write the file path I get an error message: “File Not Found.”
The file path is C:\VisualBasic\ConnectToDB\MyDatabase.mdb.
I use VB6, XP.
The Turorial:
'Connect a database to a form
Dim dbMyDB As Database
Dim rsMyRS As Recordset
Private Sub form_load()
'Attempts to open the DB
' First attempt, Set dbMyDB = OpenDatabase("MyDatabase.mdb")
' Second attempt, Set dbMyDB = OpenDatabase("C:\VisualBasic\ConnectToDB\MyDatabase.mdb")
‘Third attempt, Open App.Path & "MyDatabase.mdb" For Input As #1
Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
lstRecords.AddItem rsMyRS!Name
lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
rsMyRS.MoveNext
Loop
End Sub
Private Sub lstRecords_Click()
rsMyRS.FindFirst "ID=" & Str(lstRecords.ItemData(lstRecords.ListIndex))
txtPhone.Text = rsMyRS!Phone
End Sub
Any advice will be greatly appreciated.
-
Got it! I resolved this through the use of sheer pig headed tenacity.
-
What did you do?
If you solve your own problem, you should always post the solution you arrived at. It could help someone else, down the road, with the same or similiar problem.
(As an aside: Why are you using DAO, which is very old and outdated, rather than ADO?)
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Open DB file Resolution
This works
Code:
Private Sub form_load()
Dim sPath As String
Open "MyDatabase.mdb" For Input As #1
Set dbMyDB = OpenDatabase("MyDatabase.mdb")
Set rsMyRS = dbMyDB.OpenRecordset("MyTable", dbOpenDynaset)
If Not rsMyRS.EOF Then rsMyRS.MoveFirst
Do While Not rsMyRS.EOF
lstRecords.AddItem rsMyRS!Name
lstRecords.ItemData(lstRecords.NewIndex) = rsMyRS!ID
rsMyRS.MoveNext
Loop
End Sub
Private Sub lstRecords_Click()
rsMyRS.FindFirst "ID=" & Str(lstRecords.ItemData(lstRecords.ListIndex))
txtPhone.Text = rsMyRS!Phone
txtName.Text = rsMyRS!Name
txtMoCost.Text = rsMyRS!MoCost
txtKwh.Text = rsMyRS!kWh
End Sub
Last edited by Hack; 10-04-2010 at 06:53 AM.
Reason: Added Code Tags
-
Thank you for posting your resolution. 
(As an aside, I edited your post and added [code]your code goes here[/code] tags as it makes reading posted code a lot easier.)
Thanks again.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By partyk1d24 in forum .NET
Replies: 22
Last Post: 04-14-2013, 11:44 PM
-
By dong in forum VB Classic
Replies: 9
Last Post: 12-03-2009, 11:58 AM
-
By toecutter in forum .NET
Replies: 1
Last Post: 04-17-2006, 01:20 AM
-
Replies: 0
Last Post: 08-16-2002, 04:21 PM
-
Replies: 146
Last Post: 08-12-2002, 10:40 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks