|
-
Oct 29th, 2002, 01:11 PM
#1
Thread Starter
Junior Member
Crystal / Access - Incorrect Session Parameters
Can anyone help me please.
I have a crystal report which links to an access 2000 database. When using the report from visual basic I need to change the file location of the database depending on where the software is installed. How can this be achieved????
Please see my code so far below. --
With CrystalReport1
.SelectionFormula = ""
.ReportFileName = App.Path & "\reports\stocktakesheet.rpt"
.DataFiles(0) = App.Path & "\barcodes.mdb"
.Password = "1111111" & Chr(10)
.RetrieveDataFiles
.ReportSource = 0
.Destination = crptToWindow
.WindowControlBox = True
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
-
Oct 29th, 2002, 05:00 PM
#2
How many tables are referenced in your report? The subscript used by the DataFiles() property must agree with the order that your tables are referenced in the report. To determine the correct order, load your report in Crystal and go to Database|Set Location. Each table used by the report will be listed in its ordinal order, so the first table listed is DataFiles(0), the second is DataFiles(1) and so on.
Your code is only changing the location of the first table in your report (maybe that's what you want, I don't know). Also, there are a couple of properties you use that are superfluous.
VB Code:
With CrystalReport1
.SelectionFormula = ""
.ReportFileName = App.Path & "\reports\stocktakesheet.rpt"
.DataFiles(0) = App.Path & "\barcodes.mdb"
.Password = "1111111" & Chr(10)
[b].RetrieveDataFiles[/b] ' Get rid of this
[b].ReportSource = 0[/b] ' and this
.Destination = crptToWindow
.WindowControlBox = True
[b].PrintFileType = crptCrystal[/b] ' Used when exporting to file
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
I can't see anything fundamentally wrong with your code, the main thing I would check out is the DataFiles() property.
One other trap when using App.Path. If the current path happens to be a root directory, eg C:\, App.Path will return the path including the backslash. If it happens to be a sub-directory, eg C:\MyApp, App.Path will return the path without a trailing backslash. With this in mind, it always pays to test whether there is a trailing "\", eg
VB Code:
Dim strPath As String
If Right$(App.Path, 1) = "\" Then
strPath = App.Path
Else
strPath = App.Path & "\"
End If
Report.DataFiles(0) = strPath & "barcodes.mdb"
Hope this helps
Last edited by pnish; Oct 29th, 2002 at 05:17 PM.
-
Oct 30th, 2002, 04:08 AM
#3
Thread Starter
Junior Member
Thanks for your help!!!
The report uses just one table called "Stock". In Database|Set Location it is listed as the fifth entry down the list.
I have changed my code (see below) but still get error 20525 "Unable to Connect: incorrect session parameters"
With CrystalReport1
.SelectionFormula = ""
.ReportFileName = App.Path & "\reports\stocktakesheet.rpt"
.DataFiles(4) = App.Path & "\barcodes.mdb"
.Password = "11111" & Chr(10)
.Destination = crptToWindow
.WindowControlBox = True
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
Any other ideas?
-
Oct 30th, 2002, 07:00 AM
#4
Thread Starter
Junior Member
I have changed to Set|Locations on all tables to "same as report".
The code below works if the .DiscardSavedData = false or the "save data with report" is ticked on the file menu. Otherwise I get the same error 20535 Unable to connect: incorrect session parameters.
I need to refresh the data on each print otherwise the report is pointless.
Any ideas?
With CrystalReport1
.ReportFileName = App.Path & "\stocktakesheet.rpt"
.Destination = crptToWindow
' .DiscardSavedData = True
.WindowControlBox = True
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
-
Oct 30th, 2002, 07:15 AM
#5
Thread Starter
Junior Member
Right. If the password is taken off the database then this code will work even with the DiscardSavedData=False and save data with report unticked. Therefore the problem is with the password.
Any ideas?
With CrystalReport1
.ReportFileName = App.Path & "\stocktakesheet.rpt"
.Destination = crptToWindow
.DiscardSavedData = True
.WindowControlBox = True
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
-
Oct 30th, 2002, 07:34 AM
#6
Thread Starter
Junior Member
Problem Sorted. Just needed a chr(10) before the password.
With CrystalReport1
.ReportFileName = App.Path & "\reports\stocktakesheet.rpt"
.DataFiles(4) = App.Path & "\barcodes.mdb"
.Password = Chr(10) & "11111"
.Destination = crptToWindow
.DiscardSavedData = True
.WindowControlBox = True
.PrintFileType = crptCrystal
.WindowState = crptMaximized
.WindowMaxButton = False
.WindowMinButton = False
.Action = 1
End With
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
|
Click Here to Expand Forum to Full Width
|