Changing the path for database (*.MDB) after install (VB5 & CR6) 
Author Message
 Changing the path for database (*.MDB) after install (VB5 & CR6)

I have a VB5 application that prints (on paper and on the screen) a certain
number of reports. The data comes from 4 databases (accesfiles) from which
the data changes during the execution of the application. I made the reports
with de Crystal Report Designer ActiveX and I'm showing it via the Crystal
Reports Viewer ActiveX.
I don't use a querry since I always show the whole tables.

Problem:

    When I install the application into another directory, I always get an
error : Can't fnd file. This is normal because my files are in another
directory but in the report I coded a certain path (with the creation wizard
...)

    How do I have to tell the report where my databasefiles are ?
    Do I have to do this in the initialize event of the report ?

Please help, I'm desperate ....

Christophe



Mon, 05 Mar 2001 03:00:00 GMT  
 Changing the path for database (*.MDB) after install (VB5 & CR6)
Caveman,

1)  Create a module in VB then in general/declarations put this code

Global gPath As String
Global gDB As Database
Global gloginsucceed As Boolean

Public Const INIDATABASE = "Database"
Public Const INIPATH = "Path"
Public Const ININAME = "Financial"

Note: Financial is my dbase name so you need to use yours

2) I let the user open the database before starting an
editing/reporting.

Private Sub mnuFileOpen_Click()

    On Error Resume Next

    With dlgMain
        .MaxFileSize = 256
        .CancelError = True
        .InitDir = "c:\msoffice\access"
        .DialogTitle = "Select Database"
        .Filter = "Access (*.mdb)|*.mdb"
        .Flags = cdlOFNFileMustExist
        .ShowOpen
       End With

    If Err <> 0 Then
      If Err <> cdlCancel Then MsgBox "The file could not be opened.",
vbOKOnly + vbCritical, "Problem"
       Exit Sub
    End If

    SaveSetting ININAME, INIDATABASE, INIPATH, dlgMain.filename
    gPath = dlgMain.filename
    fSetDB

End Sub

Sub fSetDB()
On Error Resume Next
Set gDB = OpenDatabase(gPath)
If Err <> 0 Then
    MsgBox "The database has been moved.  Please open the database
before continuing. " & Err & "  " & Error(Err), vbOKOnly + vbCritical,
"Problem"
    Exit Sub
End If
End Sub

-------
Now gDB can be used anywhere in program to reference the open database.

Then use the following code when opening a report from your program:

crystalreport1.datafiles(0) = gPath

This tells crystal where the database is located.

gPath is set in the beginning of my application by making the user open
the database. Then I set gPath = to this location.

Hope this helps.

Terry



Quote:
> I have a VB5 application that prints (on paper and on the screen) a
certain
> number of reports. The data comes from 4 databases (accesfiles) from
which
> the data changes during the execution of the application. I made the
reports
> with de Crystal Report Designer ActiveX and I'm showing it via the
Crystal
> Reports Viewer ActiveX.
> I don't use a querry since I always show the whole tables.

> Problem:

>     When I install the application into another directory, I always get
an
> error : Can't fnd file. This is normal because my files are in another
> directory but in the report I coded a certain path (with the creation
wizard
> ...)

>     How do I have to tell the report where my databasefiles are ?
>     Do I have to do this in the initialize event of the report ?

> Please help, I'm desperate ....

> Christophe



Mon, 05 Mar 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB5 & CR6 - cannot find physical database

2. Q: Changing Data Sources in CR6/VB5/SQLServer

3. changing .mdb path in crystal report using vb 4.0

4. Change mdb path

5. Slow ReportSelectionFormula + Change MDB Path

6. URGENT-CR6/VB6 vbx bug with .DATAFILES-changing database location

7. VB5 & CR6

8. VB5 & CR6 - 2 Questions

9. CR6 and changing database at runtime

10. changing .mdb path in crystal report using vb 4.0

11. How to set path for database (.mdb) file ???

12. PATH-APP AND MDB-PATH

 

 
Powered by phpBB® Forum Software