Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Logo Graphic to Form 1

Status
Not open for further replies.
Feb 6, 2003
48
US
Hi-

This is a bit more complicated than simply adding a graphic to a form. The graphic is the logo of a company. I want to set up my main form so that when I enter a company, their logo appears on my form. Also, as I cycle through records already entered, I want to the logo to change to reflect the correct company for whatever record is currently selected. I have a table that lists each company and their logo. I tried created a query that joins this to the main prodcut table and then using the query as the source for my form. This put the graphic on the form, however, I couldn't add any new records or do any edits. I have been trying to figure out a way to use VBA to populate the graphic, but an not having any luck. Let me know if you have any questions. TIA for your help.

Richard
 
If your second table already has the logo stored in it, use a DLOOKUP function in the On Current event of your main table to get the correct logo. Something like

Code:
Me.LogoField = DLookup("[LogoField]", "Your LogoTable", "[CompanyID] =" _
     & Forms![Your Main Form]!CompanyID)


HTH
Lightning
 
Thanks for the reply. I do have a table that has only the company and their corresponding logo which is an OLE object data type (bitmap image). I set up my form with a unit name, unit type and company, and I added an Unbound Object (Bitmap Image object type and named it Logo) and added this code to the On Current Event:

Private Sub Form_Current()

Me.Logo = DLookup("[symbolpic]", "tblComp", "[Comp] =" _
& Forms![Testform]!Comp)

End Sub

When I open the form I get an error:
"Syntax error in string in query expression '[Comp] = WizKids'

I looked the DLOOKUP function in Help. It showed examples where a variable (varX as Variant), I tried that as well, but to no avail.
 
If the field [Comp] contains text then you'll need single quotes around the arg.

'---
Me.Logo = DLookup("[symbolpic]", "tblComp", "[Comp] ='" _
& Forms![Testform]!Comp & "'")
 
Copy this function into a new module and call it in your code:
Code:
Function MyQuotes(strSource As String) As String
'Eliminate the messy coding of Quote marks
'in a string expression or variable and make it legible
    MyQuotes = Chr$(34) & strSource & Chr$(34)
End Function

Your code would then become
Code:
Private Sub Form_Current()
    
    Me.Logo = DLookup("[symbolpic]", "tblComp", "[Comp] =" _
    & [b]MyQuotes([/b]Forms![Testform]!Comp[b])[/b])

HTH
Lightning

End Sub
 
Thanks again, that single quote function is pretty cool. I tried this and I get and "Object does not support this property or method" error. I believe that this is because 'symbolpic' is a graphic and it appears that DLookup doesn't support graphics. To test this theory, I changed the code around so that that I put a text field in an unbound text box and it worked just fine. Any other ideas? You have been most helpful by the way, I appreciate your time.
 
Yes, I thought it was pretty cool when someone gave it to me. Sure makes code easier to read.

OK, another approach is to not store the logo in the table, but store the path to the image file. Then use the Dlookup function to set the picture property of your image control.

Code:
Me.Logo.Picture = DLookup("[Your Path Field]", "tblComp", "[Comp] =" _
    & MyQuotes(Forms![Testform]!Comp))

HTH
Lightning
 
Beautiful..... It worked like a charm, all I had to do is remove the unbound object and replace it with an image. I have one more question. When I try to add a new record, I get an "Invalid use of null" error. I tried adding an If statement:

IF form_testform.comp is not null Then
....get picture
End If

I also tried form_testform.comp.value. This produced an "Object Required" error.
 
This works for me. There is a textbox on the form that displays the image path. The image control uses the image path to display the photo. If on current there is no photo path then:

Private Sub Form_Current()
On Error GoTo Err_FilePath

Dim StrPhoto, strOne, StrTwo As String

StrPhoto = Me.txtImg 'Photo Path

If IsNull(StrPhoto) Then

GoTo strOne

End If

Me.imgPhoto.Picture = StrPhoto

GoTo StrTwo

strOne:

Me.imgPhoto.Picture = ""

[CboSelItem] = [Item Number]
Me.CboSelItem.SetFocus


StrTwo:
Exit_FilePath:
Exit Sub

Err_FilePath:
MsgBox "There is probably a problem with the file Path. Please check the file path."

Resume Exit_FilePath


End Sub
 
Hi-

I believe I know what is causing the "Invalid Use of Null" Error.

The code below sets the Image control path. It compares the company on the form against the company table and return the path for the correct logo. When creating a new record, the company field on the form is blank which causes the DLookup funtion to compare a null value.

Me.Logo.Picture = DLookup("[Your Path Field]", "tblComp", "[Comp] =" _
& MyQuotes(Forms![Testform]!Comp))

My solution was to test the company field on the form and if the field is null assign the image control to a dummy graphic, like so.

Private Sub Form_Current()

If Forms![testform]!comp.Value Is Null Then
Me.Logo.Picture = "c:\test\dummy.bmp"
Else
Me.Logo.Picture = DLookup("[filepath]", "tblComp", "[Comp] =" _
& MyQuotes(Forms![testform]!comp))
End If

End Sub

I also tried removing the ".Value" from the "Forms![testform]!comp.Value" statement. This produces an "Object Required" Error. Any thoughts on how I might be able to correct this?
 
I stumbled across the answer in one of my old posts:

Private Sub Form_Current()

If IsNull(Me.comp) Then
Me.Logo.Picture = "c:\test\dummy.bmp"
Else
Me.Logo.Picture = DLookup("[filepath]", "tblComp", "[Comp] =" _
& MyQuotes(Forms![testform]!comp))
End If

End Sub

I don't know why "If IsNull(Me.comp)" works and the other way doesn't. But making that change fixed the problem.

Thanks to all who offered their help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top