Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

How can i add

Discussion in 'Information Technology' started by Michael ryan, Jul 28, 2006.

Tags:
  1. Michael ryan

    Michael ryan
    Expand Collapse
    Guest

    i am trying to put together a form where an image will also be saved at the
    same time to the database. I would like it able to browse for the image
    instead of having to use the design mode everytime to add an image, is this
    possible using access???
     
  2. Loading...


  3. Ken Sheridan

    Ken Sheridan
    Expand Collapse
    Guest

    To browse for a file there are many solutions available, but I use Bill
    Wilson's class module which is freely available from:

    http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps

    Rather than storing the images in the database, which will make the file
    very large, I'd recommend storing just the path to the file as a text field
    in the table. The image can then be loaded into an Image control (set its
    SizeMode property to Zoom) at runtime. The code to do this goes in the
    form's Current event procedure like so:

    GrabCursor

    If Not IsNull(Me.ImagePath) Then
    Me.Image1.Visible = True
    Me.Image1.Picture = Me.ImagePath
    Else
    Me.Image1.Visible = False
    End If

    ReturnCursor

    Where Image1 is the Image control on the form and ImagePath is the text
    field. The code for a button too browse to an image file and insert its path
    into the text field is:

    On Error GoTo Err_Handler

    Dim OpenDlg As New BrowseForFileClass
    Dim strPath As String
    Dim strAdditionalTypes As String, strFileList As String

    ' grab position of cursor
    GrabCursor

    ' you can change the next line if you want to list other file types
    ' when the dialogue opens
    strFileList = "*.bmp; *.jpg"
    strAdditionalTypes = "Image Files (" & strFileList & ") |" & strFileList

    ' force form to Dirty
    Me.ImageTitle = Me.ImageTitle

    ' open common 'file open' dialogue and get path to selected file
    OpenDlg.DialogTitle = "Select Image File"
    OpenDlg.AdditionalTypes = strAdditionalTypes
    strPath = OpenDlg.GetFileSpec
    Set OpenDlg = Nothing

    ' if file selected then set Picture property of Image control
    ' to path to file and enable ImageTitle control
    If Len(strPath) > 0 Then
    Me.ImagePath = strPath
    Me.Image1.Picture = strPath
    Me.Image1.Visible = True
    End If


    Exit_here:
    ' reset cursor position
    ReturnCursor
    Exit Sub

    Err_Handler:
    Select Case Err.Number
    Case 2001
    Resume
    Case Else
    MsgBox Err.Description, vbExclamation, "Error"
    Resume Exit_here
    End Select

    You'll also need to put the following module, which I name basCursor, in
    your database. This calls the Windows API to set the cursor back to its
    original position after an image is loaded; otherwise it jumps to one side:

    Option Compare Database
    Option Explicit

    Type POINTAPI
    X As Long
    Y As Long
    End Type

    Declare Function GetCursorPos Lib "User32" (lpPoint As POINTAPI) As Long

    Declare Function SetCursorPos Lib "User32" (ByVal X As Long, ByVal Y As
    Long) As Long

    Public lngCursorX As Long, lngCursorY As Long

    Public Sub GrabCursor()

    Dim dl As Long
    Dim pt As POINTAPI

    dl = GetCursorPos(pt)
    lngCursorX = pt.X
    lngCursorY = pt.Y

    End Sub

    Public Sub ReturnCursor()

    SetCursorPos lngCursorX, lngCursorY

    End Sub

    If your are using JPEGS you might want to suppress the progress dialogue
    when each image is loaded. You can find means of doing this at:

    http://www.mvps.org/access/api/api0038.htm

    If you want to show the images in a report you can do it in the same way as
    in the form, using the report's detail section's Print event procedure:

    Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

    If Not IsNull(Me.ImagePath) Then
    Me.Image1.Picture = Me.ImagePath
    Me.Image1.Visible = True
    Else
    Me.Image1.Visible = False
    End If

    End Sub

    Ken Sheridan
    Stafford, England

    "Michael ryan" wrote:

    > i am trying to put together a form where an image will also be saved at the
    > same time to the database. I would like it able to browse for the image
    > instead of having to use the design mode everytime to add an image, is this
    > possible using access???
     
  4. Larry Linson

    Larry Linson
    Expand Collapse
    Guest

    "Michael ryan" wrote

    > i am trying to put together a form where
    > an image will also be saved at the same
    > time to the database. I would like it able
    > to browse for the image instead of having
    > to use the design mode everytime to add
    > an image, is this possible using access???


    The sample imaging databases at http://accdevel.tripod.com illustrate three
    approaches to handling images in Access, and the download includes an
    article discussing considerations in choosing an approach. Two of the
    approaches do not use OLE Objects and, thus, avoid the database bloat, and
    some other problems, associated with images in OLE Objects.

    If you are printing the images in reports, to avoid memory leakage, you
    should also see MVP Stephen Lebans' http://www.lebans.com/printfailures.htm.
    PrintFailure.zip is an Access97 MDB containing a report that fails during
    the Access formatting process prior to being spooled to the Printer Driver.
    This MDB also contains code showing how to convert the contents of the Image
    control to a Bitmap file prior to printing. This helps alleviate the "Out of
    Memory" error that can popup when printing image intensive reports.

    Larry Linson
    Microsoft Access MVP
     

Share This Page