By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,626 Members | 1,657 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,626 IT Pros & Developers. It's quick & easy.

How can you insert an embedded image to a form?

P: 46
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 reports to update, and I am trying to create a tool that would standardize the design format.

First I had to update all the forms. Then the tool would be used on any new form created later.

I need to insert a banner image at the top of the form. I need to use a table so that every client has the flexibility to insert a personalized scheme.

This was the code I was using. I notice the existing forms were always labeled consistently which really helped a lot. So I try to loop through each type up to 100. Then apply a set format.

I can not get the image object to go in programatically. So I used temporarily a run command, but I need to make this table driven.

I am very new at this; I am teaching myself, and I am sure you would be able to add a lot of fine tuning. Thanks for your help.

Option Compare Database

Expand|Select|Wrap|Line Numbers
  1. '------------------------------------------------------------
  2. ' testSetProperty
  3. '
  4. '------------------------------------------------------------
  5. Function testSetProperty(frmName)
  6.  On Error GoTo testSetProperty_Err
  7.  
  8.     Dim myForm As String
  9.     Dim myFilter As String
  10.     Dim myLabel As String
  11.     Dim myCommand As String
  12.     Dim myCtrl As Control
  13.     Dim myImage As String
  14.     Dim myCombo As String
  15.  
  16.     myForm = frmName
  17.     myFilter = "Filter0"
  18.     myLabel = "Label0"
  19.     myCommand = "Command0"
  20.     myImage = "Image1"
  21.     myCombo = "Combo0"
  22.  
  23.     DoCmd.OpenForm myForm, acDesign, "", "", acEdit, acNormal
  24.  
  25.     Forms(myForm).Detail.BackColor = RGB(192, 192, 192)
  26.  
  27.     For i = 1 To 100
  28.      If funControlExists(Forms(myForm), myFilter) = True Then
  29.       Forms(myForm).Controls(myFilter).BorderColor = 8421504
  30.       Forms(myForm).Controls(myFilter).BackColor = 1677721     
  31.       Forms(myForm).Controls(myFilter).BackStyle = 1
  32.       Forms(myForm).Controls(myFilter).FontName = "Tahoma"
  33.       Forms(myForm).Controls(myFilter).FontSize = 10
  34.       Forms(myForm).Controls(myFilter).FontBold = 0
  35.      End If
  36.      myFilter = "Filter" & i
  37.     Next i
  38.  
  39.     For i = 1 To 100
  40.      If funControlExists(Forms(myForm), myCombo) = True Then
  41.       Forms(myForm).Controls(myCombo).BorderColor = 8421504
  42.       Forms(myForm).Controls(myCombo).BackColor = 16777215
  43.       Forms(myForm).Controls(myCombo).BackStyle = 1
  44.       Forms(myForm).Controls(myCombo).FontName = "Tahoma"
  45.       Forms(myForm).Controls(myCombo).FontSize = 10
  46.       Forms(myForm).Controls(myCombo).FontBold = 0
  47.      End If
  48.      myCombo = "Combo" & i
  49.     Next i
  50.  
  51.     For i = 1 To 100
  52.      If funControlExists(Forms(myForm), myLabel) = True Then
  53.       Forms(myForm).Controls(myLabel).FontName = "Tahoma"
  54.       Forms(myForm).Controls(myLabel).FontSize = 10
  55.       Forms(myForm).Controls(myLabel).FontBold = 1
  56.       Forms(myForm).Controls(myLabel).ForeColor = 0
  57.      End If
  58.      myLabel = "Label" & i
  59.     Next i
  60.  
  61.     For i = 1 To 100
  62.      If funControlExists(Forms(myForm), myCommand) = True Then
  63.       Forms(myForm).Controls(myCommand).FontName = "Tahoma"
  64.       Forms(myForm).Controls(myCommand).FontSize = 10
  65.       Forms(myForm).Controls(myCommand).FontBold = 0
  66.       Forms(myForm).Controls(myCommand).ForeColor = 0
  67.      End If
  68.      myCommand = "Command" & i
  69.     Next i
  70.  
  71.     DoCmd.RunCommand acCmdSelectAll
  72.     DoCmd.RunCommand acCmdVerticalSpacingMakeEqual
  73.     DoCmd.RunCommand acCmdSizeToFit
  74.  
  75.     If funControlExists(Forms(myForm), "Label31") = True Then
  76.      Forms(myForm).Controls("Label31").FontName = "Tahoma"
  77.      Forms(myForm).Controls("Label31").FontSize = 16
  78.      Forms(myForm).Controls("Label31").FontBold = 1
  79.      Forms(myForm).Controls("Label31").ForeColor = 16711680
  80.      Forms(myForm).Controls("Label31").Height = 350
  81.      Forms(myForm).Controls("Label31").Width = 6195.48872180451
  82.      Forms(myForm).Controls("Label31").Top = 280
  83.      Forms(myForm).Controls("Label31").Left = 0
  84.     End If
  85.  
  86.    'DoCmd.RunCommand acCmdInsertPicture
  87.    'Here I would like to insert something like:
  88.    'I really want to grab the image from a table though
  89.  
  90.     myPictureCtrl = CreateControl( myPicture)
  91.     myPictureCtrl.Name = "Image1"
  92.     myPictureCtrl.PictureType = 0
  93.     Forms(myForm).Controls("Image1").SpecialEffect = 5
  94.     Forms(myForm).Controls("Image1").Top = 0
  95.     Forms(myForm).Controls("Image1").Left = 0
  96.  
  97. testSetProperty_Exit:
  98.     Exit Function
  99.  
  100. testSetProperty_Err:
  101.     MsgBox Error$
  102.     Resume testSetProperty_Exit
  103.  
  104. End Function
  105.  
  106. Public Function funControlExists(pForm As Form, pstrCntrlName As String)
  107.  
  108.     Dim ctrl As Control
  109.     funControlExists = False
  110.  
  111.     For Each ctrl In pForm
  112.             If StrComp(ctrl.Name, pstrCntrlName, vbTextCompare) = 0 Then funControlExists = True
  113.     Next
  114.  
  115. End Function
Aug 7 '10 #1
Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,703
Here, in my opinion, is the Logic on how this should all be done:
  1. Loop thru all the Forms in the Database.
  2. Open each Form in Design, Hidden Mode.
  3. For each Form, loop thru all the Controls on the Form.
  4. Determine the Control Type of each Control on each Form.
  5. Modify Properties of each Control on each Form depending on the Control Type.
  6. Close each Form saving changes made.
  7. The following code will, on every Form:
    1. Set the FontSize of each Label to 16
    2. Set the Special Effect of each Combo Box to Sunken
    3. Set the Caption of each Command Button to Testing
    4. Set the Back Color of each text Box to Red
  8. Simulated Drumm Roll at this point!
    Expand|Select|Wrap|Line Numbers
    1. Public Function fUpdateForms()
    2. On Error Resume Next
    3. Dim intFrmCtr As Integer
    4. Dim ctl As Control
    5. Dim frm As Access.Form
    6. Dim strFormName As String
    7.  
    8. For intFrmCtr = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
    9.   strFormName = CurrentDb.Containers("Forms").Documents(intFrmCtr).Name
    10.     DoCmd.OpenForm strFormName, acDesign, , , , acHidden
    11.       For Each ctl In Forms(strFormName).Controls
    12.         Select Case ctl.ControlType
    13.           Case acLabel
    14.             ctl.FontSize = 16
    15.           Case acTextBox
    16.             ctl.BackColor = vbRed
    17.           Case acCommandButton
    18.             ctl.Caption = "Testing"
    19.           Case acComboBox
    20.             ctl.SpecialEffect = 2       'Sunken
    21.         End Select
    22.       Next
    23.       DoCmd.Close acForm, strFormName, acSaveYes
    24. Next
    25. End Function
    26.  
Aug 7 '10 #2

P: 46
Can you use this to embed an image in the form? Not as a background image, but as a banner? I want to grab the image from a table. I think I have to open a connection to the table then set it to an image object? Does that sound correct? Thank you for your help.
Aug 8 '10 #3

ADezii
Expert 5K+
P: 8,703
Vikki, I need to know exactly what you are requesting:
  1. Embedding a Picture on the Form itself as a background?
  2. Embedding a Graphic into an existing Image Control on a Form?
  3. Creating an Image Control on an existing Form, then embedding an Image in it?
  4. Table Name?
  5. Field Name in Table?
  6. Does the Field in the Table contain the Absolute Path to the Graphic File or is it an OLE Object Field?
  7. etc...
Aug 8 '10 #4

P: 46
I think it is best to use an image object and then associate it with an OLE object in a table. It has to be portable because users download a fresh copy everyday to their desktops. In this case I would like to place a small top banner on each form. I want to store the image in a table so the image could be updated by the user whenever they wanted.

I have a LogoTable with ImageReference as a field which stores a .bmp or .jpg.

I thought I could do something like

connect to the table
create the image control on the form
Name the control
set width, height, x, and y
then associate it with the image in the table
or something like that.

When I had tried the script just stopped running
so I must be either using the wrong methods
or I am not putting the correct settings, not sure

I tried connection, createcontrol, and then loadpicture

It just wasn't working.
Aug 8 '10 #5

ADezii
Expert 5K+
P: 8,703
I'll see if I can come up something tomorrow, going to bed right now.
Aug 8 '10 #6

P: 46
Thanks. Very kind of you. I'll keep trying to. There must be something.
Aug 8 '10 #7

ADezii
Expert 5K+
P: 8,703
Hello Vikki. I wrote a Code demo that is very close to what you are looking for (I have to let you have some fun and do some work (LOL)). The following Code Segment will:
  1. Open a Form (Form1) in Design Mode and Hidden.
  2. Create an Image Control on Form1 and precisely position it in the following manner:
    1. 3" from the Left edge of Form1
    2. 1/2" from the Top of Form1
    3. Make it 4" wide
    4. Make the Image Control 3/4" in Height
  3. A Graphic File (*.bmp) will be Embedded into this Image Control.
  4. The Graphic will 'Stretch' in all directions to fill the size of the Image Control.
  5. Form1 will be closed, and all changes will be Saved.
    Expand|Select|Wrap|Line Numbers
    1. Dim frm As Form
    2. Dim ctlImage As Control
    3. Dim intLeft As Integer
    4. Dim intTop As Integer
    5. Dim intWidth As Integer
    6. Dim intWidtht As Integer
    7. Dim intHeight As Integer
    8. Const conFORM_NAME As String = "Form1"
    9.  
    10. DoCmd.OpenForm conFORM_NAME, acDesign, , , , acHidden
    11.  
    12.  Set frm = Forms(conFORM_NAME)
    13.  
    14. 'Set positioning values for Image Control (1,440 Twips per Inch)
    15. intLeft = 3 * 1440              '3 inches from Left of Form
    16. intTop = 0.5 * 1440             ' .5 inch from Top of Form
    17. intWidth = 4 * 1440             '4 inches Wide
    18. intHeight = 0.75 * 1440         ' .75 inch in Height
    19.  
    20. Set ctlImage = CreateControl(conFORM_NAME, acImage, acDetail, , , intLeft, intTop, intWidth, intHeight)
    21.   ctlImage.Picture = "C:\Windows\Greenstone.bmp"
    22.   ctlImage.PictureType = 0                      'Embedded
    23.   ctlImage.SizeMode = acOLESizeStretch          'Stretch to fit Image Control
    24.  
    25. DoCmd.Close acForm, conFORM_NAME, acSaveYes
Aug 8 '10 #8

Post your reply

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