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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch board change Pic auto 1

Status
Not open for further replies.

timhans

Programmer
Jun 24, 2009
75
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. Found this on the form this morning, by ZiggyS1 answering other question

[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!

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

If Me.Filename.ItemData(n) Then n = n+1
path = "C:\Users\Documents\Pictures\pictures"
Me.Image1.Picture = path & Me.Filename.ItemData(n)
End If
not working, get mismatched data type. Thanks
 
How are ya timhans . . .

Its alot less code if the picture is selected randomly. Also my method makes the selection directly from the table. So ... in the forms [blue]On Current[/blue] event copy/paste the following:
Code:
[blue]   Dim db As DAO.Database, rst As DAO.Recordset, Pth As String
   
   Set db = CurrentDb
   Set rst = db.OpenRecordset("[purple][B][I]YourTableName[/I][/B][/purple]", dbOpenDynaset)
   Randomize [green]'set seed via system timer[/green]

   rst.MoveLast
   rst.AbsolutePosition = Int(rst.RecordCount * Rnd)
   Me!Image1.Picture = "C:\Users\Documents\Pictures\pictures" & rst![[purple][B][I]fieldname[/I][/B][/purple]]
   
   Set rst = Nothing
   Set db = Nothing[/blue]
[blue]Your Thoughts? . . .[/blue]


See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Aceman1, Perfectly done, exactly what I would have done had I the proper understanding of access. I have just started to read up on ADO, DAO, can follow most of what you did except

rst.AbsolutePosition = Int(rst.RecordCount * Rnd)

will google the various parts. Many thanks
 
timhans . . .

No need to google its in Access VBA Help. Open any code window and type [blue]absoluteposition[/blue]. Put the cursor on the word and hit [blue]F1![/blue] Its called context sensitive help. As another example ... put the cursor on the line for any form property or event and hit [blue]F1![/blue] . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top