Adamantium42
New member
- Local time
- Today, 14:11
- Joined
- Jul 30, 2013
- Messages
- 4
Good morning/evening all.
I've been following this tutorial:
Was simple enough to implement.
However I am having some trouble with having 2 different images appearing on a report.
I've attempted this by creating another table and linking to the same report as the first one has been.
This first image no the report continues to function correctly however I can't get a second one to appear. The text box with the image location is filled but the picture box remains empty.
I've played around with the code however really cannot find out how to make it work.
What I think it is to do with is the naming of the tables. The second table to get hold of the second image is named differently. I've tried accounting for this and cloning modules with new names but I've been unsuccessful.
I've followed the naming scheme given in the tutorial - except the second table has 2 as a suffix to every field/textbox/image etc.
Module Code.
Report
This would be the second setup.. same report here different fields.
Now this is the report VBA:
As you can see I only add a suffix to the field names but adding that same suffix all over the VBA does not seem to be working.
Can anyone help me with this? It must be clashing but I can't get that second image working.
Thanks guys.
Adam.
I've been following this tutorial:
Code:
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. [B]Creating the table to store file and path data[/B]
[LIST=1]
[*]Open the sample database, Northwind.mdb, or the sample project, NorthwindCS.adp.
[*]Create the following table either in Northwind.mdb or in NorthwindCS.adp.
In Northwind.mdb: Table: tblImage ---------------------------- Field Name: ImageID Data Type: AutoNumber Indexed: Yes (No Duplicates) Field Name: txtImageName Data Type: Text Table Properties: tblImage -------------------------- PrimaryKey: ImageID
In NorthwindCS.adp: Table: tblImage ----------------------- Column Name: ImageID Datatype: Int Allow Nulls: Unchecked Identity: Yes Column Name: txtImageName Datatype: varchar Table Properties: ImageTable ------------------------------- Primary Key Constraint: ImageID
[*]Open the tblImage table in Datasheet view, and then add the path and name of a bitmap file to each record. The following table of examples shows how the records might look:-------------------------------------------------------------- | Type | Example | -------------------------------------------------------------- | Absolute (Local) | C:\Windows\Zapotec.bmp | | Absolute (UNC Path) | \\Servername\sharename\Zapotec.bmp | | Relative | Zapotec.bmp | --------------------------------------------------------------
[/LIST]
[B]Creating the custom function[/B]
[LIST=1]
[*]Create a new module, and then paste or type the following code:Option Compare Database Option Explicit Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String On Error GoTo Err_DisplayImage Dim strResult As String Dim strDatabasePath As String Dim intSlashLocation As Integer With ctlImageControl If IsNull(strImagePath) Then .Visible = False strResult = "No image name specified." Else If InStr(1, strImagePath, "\") = 0 Then ' Path is relative strDatabasePath = CurrentProject.FullName intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath)) strDatabasePath = Left(strDatabasePath, intSlashLocation) strImagePath = strDatabasePath & strImagePath End If .Visible = True .Picture = strImagePath strResult = "Image found and displayed." End If End With Exit_DisplayImage: DisplayImage = strResult Exit Function Err_DisplayImage: Select Case Err.Number Case 2220 ' Can't find the picture. ctlImageControl.Visible = False strResult = "Can't find image in the specified name." Resume Exit_DisplayImage: Case Else ' Some other error. MsgBox Err.Number & " " & Err.Description strResult = "An error occurred displaying image." Resume Exit_DisplayImage: End Select End Function
[*]Save the module as Module1.
[/LIST]
[B]Using the custom function in a form[/B]
[LIST=1]
[*]Create the following new form that is based on the tblImage table. Form: frmImage ---------------------- Caption: Image Form RecordSource: tblImage Image Control --------------------------------- Name: ImageFrame Picture: "C:\Windows\Zapotec.bmp" Text box ---------------------- Name: txtImageID ControlSource: ImageID Text box --------------------------- Name: txtImageName ControlSource: txtImageName Text box --------------------------- Name: txtImageNote ControlSource: <Blank>
[B]NOTE[/B]: If you do not want the path to appear in the form, you can set the [B]Visible[/B] property of the txtImageName control to [B]False[/B].
[*]On the [B]View[/B] menu, click [B]Code[/B], and then paste or type the following code:Option Compare Database Option Explicit Private Sub Form_AfterUpdate() CallDisplayImage End Sub Private Sub Form_Current() CallDisplayImage End Sub Private Sub txtImageName_AfterUpdate() CallDisplayImage End Sub Private Sub CallDisplayImage() Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName) End Sub
[*]Open the frmImage form in Form view. Note that the form displays the corresponding bitmap for each record. If the txtImageName field is blank or if the image cannot be found, you receive appropriate messages instead of the image frame.
[/LIST]
[B]Using the custom function in a report[/B]
[LIST=1]
[*]Create the following new report that is based on the ImageTable table. Report: rptImage ---------------------- Caption: Image Report RecordSource: tblImage Image Control --------------------------------- Name: ImageFrame Picture: "C:\Windows\Zapotec.bmp" Text box ---------------------- Name: txtImageID ControlSource: ImageID Text box --------------------------- Name: txtImageName ControlSource: txtImageName Text box --------------------------- Name: txtImageNote ControlSource: <Blank>
[B]NOTE[/B]: If you do not want the path to appear in the report, you can set the [B]Visible[/B] property of the txtImageName control to [B]False[/B].
[*]On the [B]View[/B] menu, click [B]Code[/B], and then paste or type the following code:Option Compare Database Option Explicit Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer) Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName) End Sub
[*]Open the rptImage report in print preview. Note that the report displays the corresponding bitmap for each record. If the txtImageName field is blank or if the image cannot be found, you receive appropriate messages instead of the image frame.
[/LIST]
However I am having some trouble with having 2 different images appearing on a report.
I've attempted this by creating another table and linking to the same report as the first one has been.
This first image no the report continues to function correctly however I can't get a second one to appear. The text box with the image location is filled but the picture box remains empty.
I've played around with the code however really cannot find out how to make it work.
What I think it is to do with is the naming of the tables. The second table to get hold of the second image is named differently. I've tried accounting for this and cloning modules with new names but I've been unsuccessful.
I've followed the naming scheme given in the tutorial - except the second table has 2 as a suffix to every field/textbox/image etc.
Code:
Table: tblImage1 ---------------------------- Field Name: ImageID Data Type: AutoNumber Indexed: Yes (No Duplicates) Field Name: txtImageName Data Type: Text Table Properties: tblImage -------------------------- PrimaryKey: ImageID
Code:
Table: tblImage2 ---------------------------- Field Name: ImageID2 Data Type: AutoNumber Indexed: Yes (No Duplicates) Field Name: txtImageName2 Data Type: Text Table Properties: tblImage2 -------------------------- PrimaryKey: ImageID
Code:
Option Compare Database Option Explicit Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String On Error GoTo Err_DisplayImage Dim strResult As String Dim strDatabasePath As String Dim intSlashLocation As Integer With ctlImageControl If IsNull(strImagePath) Then .Visible = False strResult = "No image name specified." Else If InStr(1, strImagePath, "\") = 0 Then ' Path is relative strDatabasePath = CurrentProject.FullName intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath)) strDatabasePath = Left(strDatabasePath, intSlashLocation) strImagePath = strDatabasePath & strImagePath End If .Visible = True .Picture = strImagePath strResult = "Image found and displayed." End If End With Exit_DisplayImage: DisplayImage = strResult Exit Function Err_DisplayImage: Select Case Err.Number Case 2220 ' Can't find the picture. ctlImageControl.Visible = False strResult = "Can't find image in the specified name." Resume Exit_DisplayImage: Case Else ' Some other error. MsgBox Err.Number & " " & Err.Description strResult = "An error occurred displaying image." Resume Exit_DisplayImage: End Select End Function
Code:
Report: rptImage ---------------------- Caption: Image Report RecordSource: tblImage Image Control --------------------------------- Name: ImageFrame Picture: "C:\Windows\Zapotec.bmp" Text box ---------------------- Name: txtImageID ControlSource: ImageID Text box --------------------------- Name: txtImageName ControlSource: txtImageName Text box --------------------------- Name: txtImageNote ControlSource: <Blank>
Code:
Report: rptImage ---------------------- Caption: Image Report RecordSource: tblImage2 Image Control --------------------------------- Name: ImageFrame2 Picture: "C:\Windows\Zapotec.bmp" Text box ---------------------- Name: txtImageID2 ControlSource: ImageID2 Text box --------------------------- Name: txtImageName2 ControlSource: txtImageName2 Text box --------------------------- Name: txtImageNote2 ControlSource: <Blank>
Code:
Option Compare Database Option Explicit Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer) Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName) End Sub
Can anyone help me with this? It must be clashing but I can't get that second image working.
Thanks guys.
Adam.