Combo Box /Sub Form /Picture

bradwould

Custom User Title & Such
Local time
Today, 06:33
Joined
Nov 30, 2005
Messages
39
I was wondering if anyone could let me know how to do the following:

I have a form with a subform in it. I based the subform on a combo box that gets its info from a table seperate from the form(This works fine) when an item is selected from the combo box it retrieves the correct subform accordingly. I need to know if it is possible if when a selection is made from the combo box it could select the correct picture from the tab folder i have on the form aswell as the correct subform. The picture of my form I have attached may explain better than i can.

I appreciate any feedback whatsoever.

Thank you
 

Attachments

  • formexample3.JPG
    formexample3.JPG
    45.1 KB · Views: 155
If you simply want to change the page the Tab Control is displaying then you can change the page with:
Me.YourTabControlName = 1

It is a zero based value so the 1st Page would be 0.
 
Create an ImageFrame on your form from the Toolbox and name it ImageFrame. Also add a TextBox called txtImageNote

Create a new Module as follows

Option Explicit

Public strPath As Variant
Public intPath As Integer
Public strResult As String


Public Function DisplayImage(ctlImageControl As Control, strImagepath As Variant) As String
'
On Error GoTo Err_DisplayImage
'
'PATH to DEFAULT FOLDER
'======================
strPath = "c:\temp\" & intPath & ".jpg"
'
strImagepath = strPath
strResult = ""
'
With ctlImageControl

.Visible = True
.Picture = strImagepath

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 = "No image specified"
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


On your Form use the following code where YourComboID is the combos Primary Field number and this same number must be the relevant picture you want to use. e.g. 2.jpg is the pricture you want for combo record 2.



Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!YourComboID)
End Sub


Private Sub Form_Current()
intPath = CustomerID.Value
CallDisplayImage
If strResult = "" Then
txtImageNote.Visible = False
Else
txtImageNote.Visible = True
End If

End Sub


NOTE: most of this code was sourced from a similar question on this forum. I claim no credit for the original - only my tweaks. :cool:

Let me know how you get on. It works for me.
 
still tryin

I would like to try RuralGuy's suggestion first because it seems the fastest. Where do I enter:

Me.YourTabControlName = 1

?

I cant get it to work
 
Actually you are probably going to want a Select Case structure:
Code:
Select Case Me.[b]ComboBoxName[/b].Column(1)
Case "Labels"
   Me.[b]TabControlName[/b] = 0
Case "Transcrete1"
   Me.[b]TabControlName[/b] = 1
Case "Reed1"
   Me.[b]TabControlName[/b] = 2
Case "Oln1"
   Me.[b]TabControlName[/b] = 3
Case Else
   MsgBox "Where did [" & Me.[b]ComboBoxName[/b].Column(1) & "] come from?"
End Select
Using your ComboBoxName and your TabControlName of course. You also need to replace Column(1) with the column of your displayed text in the cbo.
 
Thank-you It is working great now. Right now when i select a model # from the combo box it displays the corresponding tab which is exactly what I wanted. Just out of curiosity is there a way to have those tabs change when previous records are selected and viewed aswell? It seems that after the initial entry the tab corresponding to the combo selection doesnt "stick" to that record. Its not a priority problem, If you are short on time i can deffinately work with what I have.

Thanks again
 
You would have to put similar code in the Current event of the form.
 
Genius

:D Pefrect, Works like a charm

Thanks again RuralGuy
 

Users who are viewing this thread

Back
Top Bottom