Handle Image In Microsoft Access

On

Access doesn't handle storing pictures very well so it's not a good idea to store them directly in the database but if you simply must, then add an ole field to your table, which is where the user would store the image.

In this chapter, we will be covering the basics of reports and how to create reports. Reports offer a way to view, format, and summarize the information in your Microsoft Access database. For example, you can create a simple report of phone numbers for all your contacts.

  • A report consists of information that is pulled from tables or queries, as well as information that is stored with the report design, such as labels, headings, and graphics.

  • The tables or queries that provide the underlying data are also known as the report's record source.

  • If the fields that you want to include all exist in a single table, use that table as the record source.

  • If the fields are contained in more than one table, you need to use one or more queries as the record source.

Example

We will now take a simple example to understand the process of creating a very simple report. For this, we need to go to the Create tab.

Before clicking on the Report button to create a basic report, make sure the proper query is selected. In this case, qryCurrentProjects is selected in your navigation pane. Now click on the Report button, which will generate a report based on that query.

You will see that the report is open in Layout view. This provides a quick way to adjust the size or width of any of your fields that you see on the report. Let us now adjust the column widths to make everything fit in a better way.

Scroll down and adjust the page control at the bottom.

This was a very quick way to create a very simple report. You could also make minor changes and adjustments from the report design view.

Microsoft
  • Just like forms, a report is made up of a variety of different sections.
  • You have the detail section, which is where all of your data lives for the most part.
  • You also will see a page header and a page footer section; these appear at the top and at the bottom of every single page in your report.

Let us now change the Title of the report and give it another name.

Click on the save icon to save your report.

Display Image In Access Form

You will get the above dialog box.

Enter a name for your report and click Ok. If you want to view what this report will actually look like, in Print Preview, you can go back to the View button and click on Print Preview to see what this report would look like when printed either on paper or as a PDF.

Using the tools on the lower right-hand corner, you can zoom in or zoom out. You also have some buttons on the Print Preview tab that appear automatically when you switch to Print Preview. In the zoom section, you've got a view for one page, two pages; or if you have a longer report, you can view four pages at once, eight pages or twelve pages. You can also adjust simple things such as the size of the paper that you are using to print, the margins for your report, the orientation, the number of columns, page set up, etc. And that is how you can create a very quick simple report using the Report button on the Create tab.

Create a Report Using Report Design

Report Design is another method for creating a quick report in Access. For this, we need to use the Report Design View button, which is like the Form Design button. This will create a blank report and open it directly to the Design View, allowing you to change the control source and add fields directly to the Design View of the report.

Let us now go to the Create tab and click on the Report Design button.

It will open a blank report or an unbound report, meaning this report is connected to no other object in our database.

On the Design tab in the Tools group, select the Property Sheet. This will open up the Property pane.

Manual

On the Data tab, assign a record source to this report, to connect it to a database object as in the following screenshot.

Select qryLateProjects from the drop-down and now, the next step is to go through and add some fields to this report by clicking on Add Existing Fields list button on the Design tab.

Select the fields as in the above screenshot.

Drag the fields to you report as in the above screenshot. Go the Arrange tab, and in the Table group, you have a couple of options to choose from.

There is a stacked layout and a tabular layout, which is a layout that is very similar to a spreadsheet. Let us select the tabular layout.

You can see that it moves all of the labels up to the page header area. These labels will appear only once at the top of every page and the data query will repeat for every record in the Details section. Now, you can go through and make some adjustments to make your ProjectName field wider.

As you can see in the above screenshot, there is a lot of space between Detail section and Page Footer.

Let us drag the Page Footer up to reduce the space as in the following screenshot. We will now go to the Design tab and click on the View button and choose Report View.

You can now see that some project names are not complete; you can adjust this with either the design view, or you can use the layout view to do that.

Access

That is how we create a simple report just from the Design View.

P: 11
i have picturedata and i want to save that to image file how i can do that
i have this function but not working for all images
  1. Function FPictureDataToClipBoard(ctl As Variant) As Boolean
  2. ' Memory Vars
  3. Dim hGlobalMemory As Long
  4. Dim lpGlobalMemory As Long
  5. Dim hClipMemory As Long
  6. ' Cf_metafilepict structure
  7. Dim cfm As METAFILEPICT
  8. ' Handle to a Memory Metafile
  9. Dim hMetafile As Long
  10. ' Which ClipBoard format is contained in the PictureData prop
  11. Dim CBFormat As Long
  12. ' Byte array to hold the PictureData prop
  13. Dim bArray() As Byte
  14. ' Temp var
  15. Dim lngRet As Long
  16. On Error GoTo Err_PtoC
  17. ' Resize to hold entire PictureData prop
  18. ReDim bArray(LenB(ctl) - 1)
  19. ' Copy to our array
  20. bArray = ctl
  21. ' Determine which ClipBoard format we are using
  22. Select Case bArray(0)
  23. Case 40
  24. ' This is a straight DIB.
  25. CBFormat = CF_DIB
  26. ' MSDN states to Allocate moveable Shared Global memory
  27. ' for ClipBoard operations.
  28. hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE Or GMEM_SHARE Or GMEM_ZEROINIT, UBound(bArray) + 1)
  29. If hGlobalMemory = 0 Then _
  30. Err.Raise vbObjectError + 515, 'ImageToClipBoard.modImageToClipBoard', _
  31. 'GlobalAlloc Failed.not enough memory'
  32. ' Lock this block to get a pointer we can use to this memory.
  33. lpGlobalMemory = GlobalLock(hGlobalMemory)
  34. If lpGlobalMemory = 0 Then _
  35. Err.Raise vbObjectError + 516, 'ImageToClipBoard.modImageToClipBoard', _
  36. 'GlobalLock Failed'
  37. ' Copy DIB as is in its entirety
  38. apiCopyMemory ByVal lpGlobalMemory, bArray(0), UBound(bArray) + 1
  39. ' Unlock the memory in preparation to copy to the clipboard
  40. If GlobalUnlock(hGlobalMemory) <> 0 Then _
  41. Err.Raise vbObjectError + 517, 'ImageToClipBoard.modImageToClipBoard', _
  42. 'GlobalUnLock Failed'
  43. Case CF_ENHMETAFILE
  44. ' New Enhanced Metafile(EMF)
  45. CBFormat = CF_ENHMETAFILE
  46. ' Create a Memory based Metafile we can pass to the ClipBoard
  47. hMetafile = SetEnhMetaFileBits(UBound(bArray) + 1 - 8, bArray(8))
  48. Case CF_METAFILEPICT
  49. ' Old Metafile format(WMF)
  50. CBFormat = CF_METAFILEPICT
  51. ' Create a Memory based Metafile we can pass to the ClipBoard
  52. ' We need to convert from the older WMF to the new EMF format
  53. ' Copy the Metafile Header over to our Local Structure
  54. apiCopyMemory cfm, bArray(8), Len(cfm)
  55. ' By converting the older WMF to EMF this
  56. ' allows us to have a single solution for Metafiles.
  57. ' 24 is the number of bytes in the sum of the
  58. ' METAFILEPICT structure and the 8 byte ClipBoard Format struct.
  59. hMetafile = SetWinMetaFileBits(UBound(bArray) + 24 + 1 - 8, bArray(24), 0&, cfm)
  60. Case Else
  61. 'Should not happen
  62. Err.Raise vbObjectError + 514, 'ImageToClipBoard.modImageToClipBoard', _
  63. 'Unrecognized PictureData ClipBoard format'
  64. End Select
  65. ' Can we open the ClipBoard.
  66. If OpenClipboard(0&) = 0 Then _
  67. Err.Raise vbObjectError + 518, 'ImageToClipBoard.modImageToClipBoard', _
  68. 'OpenClipBoard Failed'
  69. ' Always empty the ClipBoard First. Not the friendliest thing
  70. ' to do if you have several programs interacting!
  71. Call EmptyClipboard
  72. ' Now set the Image to the ClipBoard
  73. If CBFormat = CF_ENHMETAFILE Or CBFormat = CF_METAFILEPICT Then
  74. ' Remember we can use this logic for both types of Metafiles
  75. ' because we converted the older WMF to the newer EMF.
  76. hClipMemory = SetClipboardData(CF_ENHMETAFILE, hMetafile)
  77. Else
  78. ' We are dealing with a standard DIB.
  79. hClipMemory = SetClipboardData(CBFormat, hGlobalMemory)
  80. End If
  81. If hClipMemory = 0 Then _
  82. Err.Raise vbObjectError + 519, 'ImageToClipBoard.modImageToClipBoard', _
  83. 'SetClipBoardData Failed'
  84. ' Close the ClipBoard
  85. lngRet = CloseClipboard
  86. If lngRet = 0 Then _
  87. Err.Raise vbObjectError + 520, 'ImageToClipBoard.modImageToClipBoard', _
  88. 'CloseClipBoard Failed'
  89. ' Signal Success!
  90. FPictureDataToClipBoard = True
  91. Exit_PtoC:
  92. Exit Function
  93. Err_PtoC:
  94. FPictureDataToClipBoard = False
  95. MsgBox Err.Description, vbOKOnly, Err.Source & ':' & Err.Number
  96. Resume Exit_PtoC
  97. End Function
i need a function that work for all type of images like embaded on button image ole log how i can do that