'This routine checks whether:<br>
<br>
'there is a connected valid database<br>
If HerbaPathandFilename <> "" Then OpenExistDatabase: Exit Sub 'there is a valid path and file name in this variable<br>
<br>
'or whether an existing one must be browsed and connected<br>
If HerbaPathandFilename = "" Then<br>
Response = MsgBox("There is no presently no database connected to this program - do you wish to look for one", vbYesNo)<br>
If Response = vbYes Then<br>
GetHerbaPathandFilename<br>
OpenExistDatabase<br>
Exit Sub<br>
Else<br>
Response = MsgBox("Do you wish to start a new database from scratch", vbYesNo)<br>
If Response = vbYes Then<br>
MakeNewDatabase<br>
OpenExistDatabase<br>
Exit Sub<br>
Else<br>
MsgBox "Can't continue without database", vbOK: End<br>
End If<br>
End If<br>
End If<br>
End<br>
<br>
Exit Sub<br>
<br>
ErrorHandler:<br>
'there may not be a database<br>
<br>
If Err = 3078 Then<br>
Response = MsgBox("Database is not in the correct format - do you wish to create a new database", vbYesNo) 'the database is not in the correct format<br>
If Response = vbYes Then<br>
dbHerbal.Close<br>
MakeNewDatabase<br>
Resume<br>
Else<br>
End<br>
End If<br>
End If<br>
Resume Next<br>
End<br>
<br>
'unknown error<br>
ErrorRoutine = "Initialise"<br>
ErrorType = Err + Error<br>
frmFatal.Show<br>
End<br>
End Sub<br>
Public Sub OpenExistDatabase()<br>
Dim Response<br>
On Error GoTo ErrorHandler<br>
Set dbHerbal = OpenDatabase(HerbaPathandFilename) 'if an error(3024) is generated here the pathandfilename is incorrect<br>
<br>
'find out whether it is a valid database and the correct version<br>
Set rstCust = dbHerbal.OpenRecordset("Customers", dbOpenDynaset) 'if an error(3078) is generated here if the table is incorrect<br>
Set rstProducts = dbHerbal.OpenRecordset("Products", dbOpenDynaset) 'if an error(3078) is generated here if the table is incorrect<br>
Set rstSales = dbHerbal.OpenRecordset("Sales", dbOpenDynaset) 'if an error(3078) is generated here the table is incorrect<br>
Exit Sub<br>
<br>
<br>
ErrorHandler:<br>
If Err = 3024 Then 'the file could not be found<br>
Response = MsgBox("The database file could not be found - do you wish to look for it", vbYesNo)<br>
If Response = vbYes Then<br>
GetHerbaPathandFilename<br>
Resume 0<br>
Else<br>
Response = MsgBox("Do you want to open a new database", vbYesNo)<br>
If Response = vbYes Then<br>
MakeNewDatabase<br>
Resume 0<br>
Else<br>
MsgBox "The program cannot function without a database - either use an existng database or create a new one"<br>
End<br>
End If<br>
End If<br>
End If<br>
If Err = 3078 Then<br>
Response = MsgBox("Database is not in the correct format - do you wish to create a new database", vbYesNo) 'the database is not in the correct format<br>
If Response = vbYes Then<br>
dbHerbal.Close<br>
MakeNewDatabase<br>
Resume 0<br>
Else<br>
MsgBox "The program cannot function without a database - either use an existng database or create a new one"<br>
End<br>
End If<br>
End If<br>
Stop 'unhandled error<br>
End<br>
End Sub<br>
<br>
<br>
Public Sub GetHerbaPathandFilename()<br>
frmMain.cdlDatabase.Filter = "Herbadata files¦*.mdb"<br>
frmMain.cdlDatabase.ShowOpen<br>
HerbaPathandFilename = frmMain.cdlDatabase.FileName<br>
'store the filename in the .ini file<br>
Open "c:\Herbadata\Herbadata.ini" For Input As #1 'if opening this file creates an error no file exists - errorhandler<br>
'there was a file by this name<br>
Input #1, HDD<br>
Input #1, AuthoCode<br>
Close #1<br>
Open "c:\Herbadata\Herbadata.ini" For Output As #1<br>
Print #1, HDD<br>
Print #1, AuthoCode<br>
Print #1, HerbaPathandFilename<br>
Close #1<br>
End Sub<br>
<br>
Function CurrentDirectory() As String<br>
HerbaDirectory = String(145, Chr(0))<br>
HerbaDirectory = Left(HerbaDirectory, GetCurrentDirectory(145, HerbaDirectory))<br>
End Function<br>