473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to set new embedded image for bound togglebutton = true

I've got a series of toggle buttons that are bound to yes/no fields in a table. Right now, the picture for all of them in the properties section is set to BtnGray.bmp (which is embedded). I have another .bmp file (BtnBlue.bmp) that I want to display if the toggle button's state is true.

My previous attempt to work around this problem (although I'm pretty sure this is NOT the way it should be done) involved creating an unbound toggle button, setting it's visibility to "No" and calling for that picture on the AfterUpdate event of the bound toggle button.

In the code, IntSypmtPain is the bound toggle button, and ToggleBlue is the unbound button that contains the picture I want to use.

Expand|Select|Wrap|Line Numbers
  1. Private Sub IntSymptPain_AfterUpdate()
  2.  
  3. If IntSymptPain.Value = True Then
  4.     Me.IntSymptPain.Picture = Me.ToggleBlue.Picture
  5. End If
  6.  
  7. End Sub


I'm having 2 problems with my shoddy workaround:

1. I'm getting an error:
"Run-time error '2220': Microsoft Access can't open the file 'BtnBlue.bmp'."

When I click debug, the line containing "Me.IntSymptPain.Picture = Me.ToggleBlue.Picture" is highlighted.


2. This only runs on the AfterUpdate event, so when I open a form to this specific record, it doesn't try to get BtnBlue.bmp until after the button has been clicked. I know I could add the code to multiple events within the form, but seeing as I have multiple toggle buttons, wouldn't that get a little ridiculous?
Dec 15 '10 #1

✓ answered by ADezii

  1. Copy BtnBlue.bmp and BtnGray.bmp into the same Folder as your Database.
  2. Copy-N-Paste the following Sub-Procedure into the Form's Class Module, the Form containing the Toggle Buttons.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub SetTogglePicture(tgl As ToggleButton)
    2. Dim strPathToBMPs As String
    3.  
    4. strPathToBMPs = CurrentProject.Path & "\"
    5.  
    6. If tgl.Value Then
    7.   tgl.Picture = strPathToBMPs & "BtnBlue.bmp"       'True
    8. Else
    9.   tgl.Picture = strPathToBMPs & "BtnGray.bmp"       'False
    10. End If
  3. In the AfterUpdate() Event of each Toggle Button, call the Sub-Routine, passing to it the reference to the Toggle Button selected, as in:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Toggle59_AfterUpdate()
    2.   Call SetTogglePicture(Me![Toggle59])
    3. End Sub
  4. The appropriate *.BMP wil now be dynamically loaded into the Picture Property of a Toggle Button depending on its State.
P.S. - There is another alternative using 2 Unbound Toggle Controls whose Visible Properties would be set to NO, and their Images would be Embedded as opposed to dynamically Loaded. I feel as though this approach is a little cumbersome, but it does have the distinct advantage that the Images are Embedded and simply transferred to other Toggle Buttons (no concerns as far as the *.bmps being moved or deleted, and generating Errors).

3 4561
ADezii
8,834 Expert 8TB
  1. Copy BtnBlue.bmp and BtnGray.bmp into the same Folder as your Database.
  2. Copy-N-Paste the following Sub-Procedure into the Form's Class Module, the Form containing the Toggle Buttons.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub SetTogglePicture(tgl As ToggleButton)
    2. Dim strPathToBMPs As String
    3.  
    4. strPathToBMPs = CurrentProject.Path & "\"
    5.  
    6. If tgl.Value Then
    7.   tgl.Picture = strPathToBMPs & "BtnBlue.bmp"       'True
    8. Else
    9.   tgl.Picture = strPathToBMPs & "BtnGray.bmp"       'False
    10. End If
  3. In the AfterUpdate() Event of each Toggle Button, call the Sub-Routine, passing to it the reference to the Toggle Button selected, as in:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Toggle59_AfterUpdate()
    2.   Call SetTogglePicture(Me![Toggle59])
    3. End Sub
  4. The appropriate *.BMP wil now be dynamically loaded into the Picture Property of a Toggle Button depending on its State.
P.S. - There is another alternative using 2 Unbound Toggle Controls whose Visible Properties would be set to NO, and their Images would be Embedded as opposed to dynamically Loaded. I feel as though this approach is a little cumbersome, but it does have the distinct advantage that the Images are Embedded and simply transferred to other Toggle Buttons (no concerns as far as the *.bmps being moved or deleted, and generating Errors).
Dec 15 '10 #2
Thanks!! This works great!
Dec 15 '10 #3
ADezii
8,834 Expert 8TB
Glad it works for you.
Dec 16 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mrique | last post by:
hi My readers that are lotus note user receive the mails I send using cdonts with image displayed as attachement in place of inline. I read...
1
by: John Ortt | last post by:
Hi Everyone, I have an access 2003 database with a form. On the form I used to have an embedded image which depending on the data displayed was replaced with a different image using the code at...
7
by: Robert W. | last post by:
I think I'm going insane, but thought I'd check with you all first before I get myself commited! Here's a method I've built to retrieve an image: public static Image GetImage(string...
1
by: kdjgkimber | last post by:
I have one bit column in my table in SQL 2000. My dataGridView displays it as "True" or "False". What I want to do is display one image if the value was "True" and another if the value was "False".
2
by: Nhoung Ar | last post by:
Can anyone outhere advise me about a best practice of embedded the image into form or report. I have several forms and report which embedded images (logo) to the header. I observed that the...
20
by: salmanjavaheri | last post by:
Hi we have a piece of php based (i think) software that exports to an rtf file, these files contain an image, this image makes the rtfs too large...so the solution is to reduce the...
1
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi I need to add the path to my images directory to the DataUrlField of a bound ImageField in a GridView, but I can't work out how to do this. Is there a a Path property I'm missing? Or can I...
3
by: Michael R | last post by:
Hello all. I created an Image field in a table. I set it to be an OLE Object data type. Later I viewed the table in datasheet view and insereted an image to each row of the Image field. Then I...
4
by: sprad | last post by:
I have continous forms which contains the information of student cerificate that they submitted.So one student may submitted two or three ceriticate.I have one button name display image in form for...
7
by: Vikki McCormick | last post by:
I have an old database which was developed over time and contains forms with a variety of formats, and the owners would like the user interface updated to a new design. I had a lot of forms and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.