-
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?)
-
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.
Similar Threads
-
By partyk1d24 in forum .NET
Replies: 26
Last Post: 03-28-2014, 01:49 AM
-
By dong in forum VB Classic
Replies: 9
Last Post: 12-03-2009, 12:58 PM
-
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|