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!

Dynamically read table data to button picture data

Status
Not open for further replies.

Tazcat

Technical User
Feb 17, 2003
40
US
Ok, here's the problem. I have one form, Details, which has a boat load of buttons on it. I created a "help" file, which gives descriptions for each button, and what it does. I have everything else working OK, but now comes the fun part. I am trying to read the button name from a table, and pass it to the picturedata of a 'display' button on the help form, which will change the picture show. I've done something similar on another form and it works fine, but that was hard-coding the picturedata source. Now, I'm trying to read it in from a table. In all honestly, I've been playing with this so long, my code looks like spaghetti. Need a fresh pair of eyes to tell me where I screwed up. Here's the code:


Option Compare Database
Dim cn As Connection
Dim rs As Recordset
Dim stButton As String

Private Sub Form_Load()
Set cn = CurrentDb.Connection
Set rs = New Recordset

rs.Open "tblButtonHelp", cn

End Sub

Public Sub Form_Current()
Dim stField As String

stField = Me.RecordID.Text

DoCmd.FindRecord stField
stButton = rs!ButtonName

Me.Button.PictureData = Form_Detail.stButton.PictureData

End Sub
 
Change that last line before the End Sub to:
Code:
    Me.Button.PictureData = Form_Detail.Controls(stButton).PictureData

I'm not sure about that "Form_Detail" though. You said the form name was "Details". Is that supposed to be a reference to the default instance, Form_Details?

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
it's really Form_Detail. I mistyped the name when I was describing the problem. Thanks for your help, but I'm finding it doens't matter what I do, the button image wont change, even if I am using the other method I'd tried before (hiding multiple buttons on the form, and then changing the picturedata through an if statment fired off by some change event, like the click.) Unfortunately, none of the events seems to trigger the if to run, and I can't figure out why.

This function really wasn't important to my project, it just would have looked really cool, that's all.

Thanks again for the help.
 
There's no reason this shouldn't work. I do something similar on one of my forms, in fact.

You said "none of the events seems to trigger the if to run". Are you saying that you set a breakpoint on the If statement, which is in a Click event procedure, and it was never executed when you clicked the button? I believe the only way that could be is if the button's OnClick property wasn't set to "[Event Procedure]". If you paste an event procedure into a module, Access is supposed to automatically set the event property for you, but sometimes it doesn't work and you have to set the property manually.

In the code you gave in your original question, I wondered about "DoCmd.FindRecord stField". For that to work, stField has to contain a criteria expression, such as "RecordId = 100". In this code, it looks as if it just has the value "100". In that case, the FindRecord would just give you an error, and all the fields in the recordset would be left Null. Then, when you assign the Null value to the PictureData property, it leaves the button blank. Perhaps that's why this didn't work.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top