You'll need a global varibale to store the path to the db. Put this into a module
Code:
Public strDBPath As String
Public Function FileExists(strPath As String) As Boolean
On Error Resume Next
Dim lngRetVal As Long
lngRetVal = Len(Dir$(strPath))
If Err Or lngRetVal = 0 Then
FileExists = False
Else
FileExists = True
End If
End Function
You need some way to check if the file exists before trying to read from it, so use this code when your app first starts. Put a common dialog control on a form and paste this code
Code:
'Set to default path
If Right(App.Path, 1) <> "\" Then
strDBPath = App.Path & "\maths.mdb"
Else
strDBPath = App.Path & "maths.mdb"
End If
'check to see if exists
If FileExists(strDBPath) <> True Then
'file does not exists, show Open file dialog. Put a commonddialog control on a form
' Set CancelError is True
CommonDialog1.CancelError = False
' Set flags
CommonDialog1.flags = cdlOFNHideReadOnly
' Set filters
CommonDialog1.Filter = "MDB File (*.mdb)|*.mdb"
' Specify default filter
CommonDialog1.FilterIndex = 1
' Display the Open dialog box
CommonDialog1.ShowOpen
' Display name of selected file
strDBPath = CommonDialog1.FileName
End If
strDBPath now contains the path to the db, whether it is where it is supposed to be, or somewhere they have selected. You will need to change this
Code:
Set High_Score = OpenDatabase("maths.mdb")
To this
Code:
Set High_Score = OpenDatabase(strDBPath)