Results 1 to 3 of 3

Thread: Confused About Database Problem!

  1. #1

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909

    Confused About Database Problem!

    Below i have my code for accesing a database and when i move where the exe file and database are located on my computer it gives me error cannot find path. C:\Windows\Desktop\Project\db1.mdb

    Why does it do this when my code is:

    Set DB = DAO.OpenDatabase(App.Path & "\db1.mdb")

    The Database is accessed from a different form with this code:
    VB Code:
    1. Private Sub Command1_Click()
    2. Load frmMovieInfo
    3. frmMovieInfo.Show
    4. Call frmMovieInfo.Memento
    5. End Sub

    Database Code:
    VB Code:
    1. Dim DB As Database
    2. Dim rs As Recordset
    3.  
    4. Private Sub cmdNext_Click()
    5.     FillFields
    6.    
    7.     rs.MoveNext
    8.     If rs.EOF Then
    9.     rs.MoveFirst
    10.    
    11. End If
    12. End Sub
    13.  
    14. Public Sub AI()
    15. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'A.I. : Artificial Intelligence' ")
    16.     FillFields
    17. End Sub
    18.  
    19. Private Sub Form_Load()
    20. Set DB = DAO.OpenDatabase(App.Path & "\db1.mdb")
    21. End Sub
    22.  
    23. Private Sub cmdPrevious_Click()
    24.     FillFields
    25.    
    26.     rs.MovePrevious
    27.     If rs.BOF Then
    28.     rs.MoveLast
    29. End If
    30. End Sub
    31.  
    32. Public Sub FillFields()
    33.     txtPlot.Text = rs.Fields("Plot")
    34.     txtTitle.Text = rs.Fields("Title")
    35.     txtYear.Text = rs.Fields("Year")
    36.     txtGenre.Text = rs.Fields("Genre")
    37.     txtFormat.Text = rs.Fields("Format")
    38.     txtSize.Text = rs.Fields("Size")
    39.     txtUploader.Text = rs.Fields("Uploader")
    40.     txtSoundQ.Text = rs.Fields("SoundRating")
    41.     txtPlotQ.Text = rs.Fields("Plot Rating")
    42.     txtQualityQ.Text = rs.Fields("QualityRating")
    43.     Image1.Picture = LoadPicture(rs.Fields("Picture") & "")
    44. End Sub
    45.  
    46. Private Sub Picture2_Click()
    47. Unload Me
    48. End Sub
    49.  
    50. Public Sub Animal()
    51. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'The Animal' ")
    52.     FillFields
    53. End Sub
    54.  
    55. Public Sub Atlantis()
    56. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Atlantis: The Lost Empire' ")
    57.     FillFields
    58. End Sub
    59.  
    60. Public Sub Memento()
    61. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Memento' ")
    62.     FillFields
    63. End Sub
    64.  
    65. Public Sub FinalFantasy()
    66. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Final Fantasy: The Spirits Within' ")
    67.     FillFields
    68. End Sub
    69.  
    70. Public Sub Pearlharbor()
    71. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Pearl Harbor' ")
    72.     FillFields
    73. End Sub
    74.  
    75. Public Sub Shrek()
    76. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Shrek' ")
    77.     FillFields
    78. End Sub
    79.  
    80. Public Sub Swordfish()
    81. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Swordfish' ")
    82.     FillFields
    83. End Sub
    84.  
    85. Public Sub Tommyboy()
    86. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Tommy Boy' ")
    87.     FillFields
    88. End Sub
    89.  
    90. Public Sub MenofHonor()
    91. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Men Of Honor' ")
    92.     FillFields
    93. End Sub
    94.  
    95. Public Sub ScaryMovie2()
    96. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Scary Movie 2' ")
    97.     FillFields
    98. End Sub
    99.  
    100. Public Sub Bedazzled()
    101. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'Bedazzled' ")
    102.     FillFields
    103. End Sub
    104.  
    105. Public Sub TheUsualSuspects()
    106. Set rs = DB.OpenRecordset("Select * From Table1 Where Title = 'The Usual Suspects' ")
    107.     FillFields
    108. End Sub

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    Instead of using app.path why dont you provide the end user with the option of locating the database. That way if they want to move it from the apps install folder your program isnt going to fall over.

    You could even make your app super smart and (if your db is going to be statically named) get it to search the drive for the database and set path into a reg entry or something


  3. #3

    Thread Starter
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    I figured it out. Sorry for the wasted post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width