switch Board change pic

timothyl

Registered User.
Local time
Today, 03:13
Joined
Jun 4, 2009
Messages
92
Hello. I have a switch board(Not made with wizard)it has a picture on it, would very much like for picture to change when switch board is opened.

Private Sub Form_Current()
Dim path As String

'The Me.Filename is the name of a text box that holds the filename. As you change records if you have the field filled in with a valid filename the image will appear.
If Me.Filename <> "" Then
path = "C:\Users\Documents\Pictures\pictures"
Me.Image1.Picture = path & Me.Filename
End If

End Sub
Works good! (Thanks ZiggyS1)

I have created a table with the names of my pictures and a combobox populated by a select statement from this table.
Need help in how to auto move to next position in combobox on, on current event(or some better idea), attempting

Private Sub Form_Current()
On Error GoTo Error_Handler

Dim path As String

'The Me.Filename is the name of a text box that holds the filename. As you change records if you have the field filled in with a valid filename the image will appear.

If Me.FileName <> "" Then
Me.FileName.ListIndex = Me.FileName.ListIndex + 1

path = "C:\Users\Timothy L Hanson\Pictures\pictures\"
Me.Image1.Picture = path & Me.FileName & ".jpg"

Error_Handler:
If Err.Number = 7777 Then
' End of the list - Move to the start.
Me.FileName.ListIndex = 0
Exit Sub
Else
MsgBox Err.Description, vbOKOnly, "Error #" & _
Err.Number & " occurred"
End If
End If

End Sub
not working keep getting Err 7777
 
Last edited:
The perfect solution, Thanks- theAceMan1, where yourTableName is a table of your picture names, not a table of pictures.

In the forms On Current event copy/paste the following:

Dim db As DAO.Database, rst As DAO.Recordset, Pth As String

Set db = CurrentDb
Set rst = db.OpenRecordset("YourTableName", dbOpenDynaset)
Randomize 'set seed via system timer

rst.MoveLast
rst.AbsolutePosition = Int(rst.RecordCount * Rnd)
Me!Image1.Picture = "C:\Users\Documents\Pictures\pictures" & rst![fieldname]

Set rst = Nothing
Set db = Nothing
 
Last edited:
Thanks for posting back with the solution. It is highly appreciated considering you got the answer elsewhere and most don't come back and post the answer if it came from another forum. Thank you, very much for being the rare exception. :)
 

Users who are viewing this thread

Back
Top Bottom