The LoadPicture function loads a graphic into a custom control.
LoadPicture(stringexpression)
The LoadPicture function uses the following argument.
Argument |
Description |
stringexpression |
The filename of the graphic to be loaded. The graphic can be a bitmap file (.bmp), icon file (.ico), run-length encoded file (.rle), or metafile (.wmf). |
Assign the return value of the LoadPicture function to the Picture property of a custom control to dynamically load a graphic into the control. The following example loads a bitmap into a control called OLECustomControl on an Orders form.
Set Forms!Orders!OLECustomControl.Picture = LoadPicture("Stars.bmp")
The LoadPicture function returns an object of type Picture. You can assign this value to a variable of type Object using the Set statement.
The Picture object is not a Microsoft Access object, but it is available to procedures in Microsoft Access. If you wish to assign the return value of the LoadPicture function to an object variable of type Picture, you must first set a reference to the Standard OLE Types type library in the References dialog box, available by clicking References on the Tools menu. You can then declare an object variable of type Picture.
Note You can’t use the LoadPicture function to set the Picture property of an image control. This function works with custom controls only. To set the Picture property of an image control, simply assign to it a string specifying the filename and path of the desired graphic.
The following example uses the LoadPicture function to load a metafile into a custom control on an Employees form. Note that in order to declare a variable of type Picture, you must set a reference to the Standard OLE Types type library in the References dialog, available by clicking References on the Tools menu.
Sub DisplayGraphic() ' Declare object variables of type Picture and Control. Dim pic As Picture, ctl As Control ' Set Control variable to refer to custom control on form. Set ctl = Forms!Employees!SomeCustomControl ' Assign return value of LoadPicture to Picture object. Set pic = LoadPicture("C:\MSOffice\Access\Bitmaps\Styles\Globe.wmf") ' Set Picture property of custom control. Set ctl.Picture = picSub