Images in data reports

webstaff
01-13-2004, 09:48 AM
Hi Guys,

Ive made a simple report in the VB6 reports designer, its working fine except for the images, each record has a small pic and its path is stored in the database field "field_photo"
When I run the form and click my command button I get the error message "Subscript out of range" and highlights this line "DataReport1.Sections(1).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\" & picone)
"

the forms command button that calls the report has the following code

Private Sub Command5_Click()
Dim rs2 As DAO.Recordset
Dim db2 As DAO.Database
Dim strConnect
strConnect = ";DATABASE=" & App.Path & "\mydb.mdb" & _
";PWD="

Set db2 = OpenDatabase("", False, False, strConnect)
Set rs2 = db2.OpenRecordset("SELECT * " & _
"FROM sbt " & _
"WHERE field_name = '" & Text1.Text & "'")
picone = rs2.Fields("field_photo")
DataReport1.Sections(1).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\" & picone)
DataReport1.Refresh
DataReport1.Show
Set rs2 = Nothing

End Sub

webstaff
01-14-2004, 05:04 AM
Hey Guys,
I have tried a different approach to this report, Ive used an ADO connection and kept the report realy simple with 2 Report textboxes and a report Image.
This code runs on the textboxes but when i add the code
".Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")
" in the with statment I get the error message
"Object Doesnt support this property or method"
This is my first attempt at a VB Report and I would appreciate any thoughts.
Many thanks

Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim sSql As String
mySql = "select * from table1"
cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & App.Path & "\MYDB.mdb;" & _
"Uid=;" & _
"Pwd="

rs.Open mySql, cn, adOpenKeyset, adLockOptimistic

Set DataReport1.DataSource = rs
rs.MoveFirst
While rs.EOF = False

With DataReport1.Sections("section1")

.Controls("text1").DataField = rs.Fields("field_photo").Name
.Controls("text2").DataField = rs.Fields("field_name").Name
.Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")

End With
rs.MoveNext

Wend


DataReport1.Show

End Sub

Shurik12
01-14-2004, 05:50 AM
Hi,

Could you try the following:


Set DataReport1.Sections(3).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")



Regards,
Shurik.

webstaff
01-14-2004, 09:01 AM
Thanks,
This gives the same error.

I did read in a post that the RPT Image controls cannot be loaded at runtime, would this be the case here even though I have the code written before the report is called?

If this is the case can anyone suggest a workaround for this?
Thanks again
W

Shurik12
01-14-2004, 09:40 AM
Well,
I just tested it on my PC and it seemed to work OK.

On a Form1 I had button :



Private Sub Command1_Click()

Set DataReport1.Sections(3).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")

End Sub

DataReport1.Show



the report showed up with the picture next to each of teh records in the 'detail' section.

Please also make sure (just in case) that you are referencing the correct
Section of the report ...Sections(1).Controls("Image1"). Is it really were your image control is situated?

shminhas
01-14-2004, 11:23 AM
The following Code is running but the pictures are not changing corresponding to records. Only picture with "Set" datareport1 command is repeating(Green Color).


Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim sSql As String
mySql = "select * from table1"
cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & App.Path & "\MYDB.mdb;" & _
"Uid=;" & _
"Pwd="

rs.Open mySql, cn, adOpenKeyset, adLockOptimistic

Set DataReport1.DataSource = rs
rs.MoveFirst
While rs.EOF = False

With DataReport1.Sections("section1")

.Controls("text1").DataField = rs.Fields("field_photo").Name
.Controls("text2").DataField = rs.Fields("field_name").Name
End With

et DataReport1.Sections(3).Controls("Image1").Picture = LoadPicture(rs.Fields("path"))

rs.MoveNext

Wend


DataReport1.Show

End Sub


Note:
Path is a field in which the path of picture is stored. But how can picture will be changed with each record from the report

webstaff
01-14-2004, 02:11 PM
When I try the following i get a subscript out of range error.

Set DataReport1.Sections(3).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")



And if I have (As section1 is the detail section on my report and thats where the Image1 control is) I get the object does not support this property or method??


Set DataReport1.Sections(1).Controls("Image1").Picture = LoadPicture(App.Path & "\pictures\no_pic.gif")


What is wrong here if it ran ok on your PC?
Also why do you make mention to DataReport1.Sections(3), in my report this section is the footer of the document?

Regards
W

shminhas
01-14-2004, 02:27 PM
But also this code is running correctly but Pictures are changing corresponding to Records. U just copy and paste and add controls according to the following. And reply me.......Whats happend


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim sSql As String

Private Sub Command1_Click()
Set DataReport1.DataSource = rs
rs.MoveFirst
While rs.EOF = False
With DataReport1.Sections("section1")

.Controls("text1").DataField = rs.Fields("field_name").Name

End With
pic = rs.Fields("path")
Set DataReport1.Sections("section1").Controls("Image1").Picture = LoadPicture(pic)

rs.MoveNext

Wend

DataReport1.Refresh
DataReport1.Show

End Sub


Private Sub Command2_Click()

Set DataReport1.Sections(3).Controls("Image1").Picture = LoadPicture(App.Path & "\" & "no_pic.gif")

'Print "'" & rs.Fields("Path") & "'"
End Sub

Private Sub Form_Load()
mySql = "select * from table1"
cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & App.Path & "\MYDB.mdb;" & _
"Uid=;" & _
"Pwd="

rs.Open mySql, cn, adOpenKeyset, adLockOptimistic
End Sub

shminhas
01-14-2004, 02:30 PM
But also this code is running correctly but Pictures are changing corresponding to Records. U just copy and paste and add controls according to the following. And reply me.......Whats happend


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim sSql As String

Private Sub Command1_Click()
Set DataReport1.DataSource = rs
rs.MoveFirst
While rs.EOF = False
With DataReport1.Sections("section1")

.Controls("text1").DataField = rs.Fields("field_name").Name

End With
pic = rs.Fields("path")
Set DataReport1.Sections("section1").Controls("Image1").Picture = LoadPicture(pic)

rs.MoveNext

Wend

DataReport1.Refresh
DataReport1.Show

End Sub

Private Sub Form_Load()
mySql = "select * from table1"
cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & App.Path & "\MYDB.mdb;" & _
"Uid=;" & _
"Pwd="

rs.Open mySql, cn, adOpenKeyset, adLockOptimistic
End Sub

Note :
the User Shurik12 replied that the Pics are changing in DataReport

webstaff
01-14-2004, 03:32 PM
Hey shminhas,
That worked a treat, thanks very much!!
Regards
w

shminhas
01-14-2004, 03:39 PM
Thats great....But My problem is that the picture should be change correspoding to Records showing in DataReport. The Last Record's Picture Path is repeating with all records...

like Employee name along with its picture and so on in every page

Please Solve My Problem...

Thanx in Advance

webstaff
01-14-2004, 04:43 PM
Thats great....But My problem is that the picture should be change correspoding to Records showing in DataReport. The Last Record's Picture Path is repeating with all records...

like Employee name along with its picture and so on in every page

Please Solve My Problem...

Thanx in Advance

What I did to get the image to change depending on the record pulled by the recordset was
pic = App.Path & "\pictures\" & rs.Fields("field_photo")
In my database i hold only the image name as saving the image itself in the database seemed to bloat the database.
Hope thats what you mean.....

shminhas
01-15-2004, 01:59 AM
I Develop the following code. But Images are not changed with records in DataReport


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim sSql As String

Private Sub Command1_Click()
Set DataReport1.DataSource = rs
rs.MoveFirst
While rs.EOF = False
With DataReport1.Sections("section1")

.Controls("text1").DataField = rs.Fields("field_name").Name

End With
pic = rs.Fields("path")
Set DataReport1.Sections("section1").Controls("Image1").Picture = LoadPicture(pic)
rs.MoveNext

Wend

DataReport1.Refresh
DataReport1.Show

End Sub

Private Sub Form_Load()
mySql = "select * from table1"
cn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & App.Path & "\MYDB.mdb;" & _
"Uid=;" & _
"Pwd="

rs.Open mySql, cn, adOpenKeyset, adLockOptimistic
End Sub

Shurik12
01-15-2004, 02:19 AM
Hi,

I just noticed that you have this in your code


[vb]
While rs.EOF = False
....
Wend
[vb]

I'm not sure you need it (for you have Set DataReport1.DataSource = rs in your code after all, right?)


Regards,
Shurik.

shminhas
01-15-2004, 03:14 AM
If I omit the loop the the records will not print dynamically in the Datareport.

I am in Problem to prepare Datareport with list of Employee name and their picture, which are store in Database of Access.

Please assist me how it will possible.

Thanx in advance

Shurik12
01-15-2004, 03:37 AM
Well what I'd suggest is that you attach you project so that I (or other people of course) could have a look at it.
Hope it's feasible for you. May be it's not neccesary to send the whole thing but a form you're calling the report from and the access database.

(Just in case I'm not going to be able to check it right now for I have VB6 on the development line which is naturally separated from the outer world) On coming back home tonight I could try to have a look at it.

Regards,
Shurik.

shminhas
01-15-2004, 05:54 AM
Please find to enclosed Program.....for ur suggestion.

shminhas
01-15-2004, 05:58 AM
This is the Source Code

Shurik12
01-15-2004, 06:18 AM
..something went wrong with the attachment.

shminhas
01-15-2004, 06:27 AM
Sorry find the Source Code....

shminhas
01-15-2004, 03:56 PM
Please Help me......... I have described the problem, for this purpose I have attached my previous posted reply...

Shurik12
01-15-2004, 04:35 PM
Well, tried to play around with your code. no solution so far...
(although something similar seems to be working in the Access report).
Sorry to tired today to try to investigate it further.
Will try to come back on this later.

Regards,
Shurik.

shminhas
01-15-2004, 04:43 PM
Thanx for your cooperation and give time on my code. Actually I don't have vast experience in Access.

Will it possible to solve my problem using Access Report. I store the data in table and show report from access using VB Program.

Thanx again

Dennis DVR
01-16-2004, 01:10 AM
hi
i've read your post but sad to say datareport does not support multiple images in one image control it will just print the last image that you assigned to image control becuase the picture is not immidiately printed but rather the datareport prepares it for printing so assingning multiple picture to image control will just overwrite the old one and the last one will be printed.

I think you need a report desginer that has an ole control and can bind to a database

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum