Solved

Get images from access database to vb application

Posted on 2003-11-27
13
13,690 Views
Last Modified: 2013-12-25
Hi!
I've got an Access database with bitmaps that I want to show in an image-control i my application. What's the code for that? I've tried to bind it to my adodc control as I've done with my other controls but it doesn't work.
/catti
0
Comment
Question by:catti
  • 9
  • 3
13 Comments
 
LVL 8

Expert Comment

by:MYLim
ID: 9830484
August 17, 2001

Using the ADO Stream Object to Manage BLOBs

The following is an unedited excerpt from my new book ADO Examples and Best Practices—2nd  Edition (Apress) due out this fall. I hope it proves helpful to developers who are struggling with the ADO Chunk methods. Watch http://www.betav.com/ for updates.

 

Since ADO 2.5, the Stream object has evolved into a pivotal component in the ADO data access paradigm. As we will see in later chapters, streams play an even more critical role in ADO.NET. As developers discover the flexibility and performance of Stream objects, and how well they integrate into ADO, I expect more and more code to include routines driven from Stream IO. The Stream is basically an in-memory data structure that can be used to persist columns, entire Recordsets, or virtually any form of data. Since developers often have to extract BLOB data from Recordsets into memory and immediately save this data to files, ADO’s Stream object is an ideal mechanism for managing these large blocks of binary or text data.

In the following example, you’ll see that in order to fetch a BLOB you simply need to return a Recordset containing the data and use the Stream object to extract the data from the Field.Value property. To save a BLOB, reverse the process, filling the Value property from the Stream. Once you set the Field.Value, all you need to do is use the Recordset Update method to save it—ADO takes care of the rest.

Note: Just before this section, the book discusses why you should avoid putting Binary Large Objects (BLOBs) in the database in the first place. This example is intended for those who have already decided to do so against my advice.

The first routine after the object setup declarations executes a stored procedure that returns all of the Cover images from the database whose titles match a given string.

Option Explicit

Dim cn As ADODB.Connection

Dim cmd As ADODB.Command

Dim rs As ADODB.Recordset

Dim stm As ADODB.Stream

Dim fso As FileSystemObject

 

Private Sub btnFindPicture_Click()

If rs.State = adStateOpen Then rs.Close

cn.GetCoverByTitle txtTitleWanted.Text, rs

If rs.RecordCount > 0 Then

    GetAndShowPicture rs

    If rs.RecordCount > 1 Then

        btnNextPicture.Enabled = True

    Else

        btnNextPicture.Enabled = False

    End If

Else

    MsgBox "No picture on file for this title"

End If

End Sub

 

This next routine (GetAndShowPicture) fetches the binary Cover column from the Recordset, and in one operation saves it to a temporary file (destroying any existing temp file by the same name in the process). The routine turns around and immediately uses this file to load an image control used to display the file in a WinForm application.

Sub GetAndShowPicture(rs As ADODB.Recordset)

Dim strTempFilename As String

strTempFilename = App.Path & "\" & fso.GetTempName

 

Set stm = New ADODB.Stream

With stm

    .Open

    .Type = adTypeBinary

    .Write rs.Fields("Cover").Value

    .SaveToFile strTempFilename, adSaveCreateOverWrite

   

End With

Image1.Picture = LoadPicture(strTempFilename)

Kill strTempFilename

End Sub

 

The Stream object can also be used to save BLOB data to the database. The following example saves TEXT data from a text file to the database using an updatable Recordset. Frankly, this scenario is a bit contrived as I would be hesitant to use an updatable Recordset for this task—I would much more likely use an UPDATE statement or a stored procedure. However, this is really pretty easy so it does have some appeal, but I also expect the overhead to be somewhat higher than query techniques I’ve already discussed.

The following example (yes, it’s on the CD that comes with the book), opens a file (based on the CommonDialog control), and uses the ADO Stream object to open it. The same stream object is used as a source to pass to the Recordset Value property. Yes, I created an updatable Recordset for this example. Not that I wanted to, but it was necessary for this example.

Option Explicit

Dim cn As ADODB.Connection

Dim cmd As ADODB.Command

Dim rs As ADODB.Recordset

Dim stm As ADODB.Stream

Dim PubIDFound As Integer

 

Here we choose a file and use the Stream to open it as an ASCII file. Of course this approach could also be used to read binary files (such as Microsoft Word or Excel documents) just as easily, but you’ll have to change a few of the Stream properties to accommodate the binary file content. In this case I set the Stream Charset property to “ASCII” to reflect that I’m reading files created with Visual Notepad. If you don’t use this option, the Stream defaults to Unicode and the Visual Basic TextBox (and most other “Windows-based” controls don’t know how to display Unicode—so you get lots of “?” characters).

Tip: You can use the Visual Basic “Lightweight” controls to display Unicode

Private Sub btnGetFilename_Click()

With CommonDialog1

    .ShowOpen

    txtFileName.Text = .FileName

    txtComments.FileName = .FileName

End With

Set stm = New ADODB.Stream

With stm

     .Charset = "ascii"

     .Open

     .LoadFromFile txtFileName.Text

     .Position = 0

    txtComments.Text = .ReadText

End With

Next, the code reads from the Stream and writes to the Value property. Notice that I set the Stream Position property to start reading from the first (0) character of the Stream.

End Sub

Private Sub btnSaveBLOB_Click()

    stm.Position = 0

    rs.Fields("Comments").Value = stm.ReadText  ' Read from Stream into the Column

    rs.Update

End Sub

'Folks, it does not get much easier than that.
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9830493
'2nd:Save/Retrieve Image From SQL Server Database Using Ado 2.5 Stream Object
'***************************************************************
'* Save/Retrieve Image Data From SQL Server DataBase Using
'* ADOStream Objects.
'***************************************************************
'* Code By: Michael P. Gerety
'***************************************************************
Dim rstRecordset As ADODB.Recordset
Dim cnnConnection As ADODB.Connection
Dim strStream As ADODB.Stream

'*Setup:
'*Create a form and place 3 command buttons named:
'*cmdLoad, cmdSelectSave, and cmdClear
'*Place a CommonDialog Control Named Dialog
'*Place an ImageBox (or PictureBox) named Image1


'** The field type in Sql Server must be "Image"
'** Everywhere you see "***" in the code is where you must enter
'** your own data.

Private Sub cmdClear_Click()
    Image1.Picture = Nothing
   
End Sub

Private Sub cmdLoad_Click()
    If Not LoadPictureFromDB(rstRecordset) Then
        MsgBox "Invalid Data Or No Picture In DB"
    End If
End Sub

Private Sub cmdSelectSave_Click()
    'Open Dialog Box
    With dlgDialog
        .DialogTitle = "Open Image File...."
        .Filter = "Image Files (*.gif; *.bmp)| *.gif;*.bmp"
        .CancelError = True
procReOpen:
         .ShowOpen
         
        If .FileName = "" Then
            MsgBox "Invalid filename or file not found.", _
                vbOKOnly + vbExclamation, "Oops!"
            GoTo procReOpen
        Else
            If Not SavePictureToDB(rstRecordset, .FileName) Then
                MsgBox "Save was unsuccessful :(", vbOKOnly + _
                        vbExclamation, "Oops!"
                Exit Sub
            End If
        End If
           
    End With
End Sub

Private Sub Form_Load()
    Set cnnConnection = New ADODB.Connection
    Set rstRecordset = New ADODB.Recordset

    cnnConnection.Open ("Provider=SQLOLEDB; " & _
        "data Source=**YourServer**;" & _
        "Initial Catalog=**YourDatabase**; " & _
        "User Id=**YourUID**;Password=***YourPass***")
    rstRecordset.Open "Select * from YourTable", cnnConnection, _
         adOpenKeyset, adLockOptimistic
   

End Sub


Public Function LoadPictureFromDB(RS As ADODB.Recordset)

    On Error GoTo procNoPicture
   
    'If Recordset is Empty, Then Exit
    If RS Is Nothing Then
        GoTo procNoPicture
    End If
   
    Set strStream = New ADODB.Stream
    strStream.Type = adTypeBinary
    strStream.Open
   
    strStream.Write RS.Fields("**YourImageField**").Value

   
    strStream.SaveToFile "C:\Temp.bmp", adSaveCreateOverWrite
    Image1.Picture = LoadPicture("C:\Temp.bmp")
    Kill ("C:\Temp.bmp")
    LoadPictureFromDB = True

procExitFunction:
    Exit Function
procNoPicture:
    LoadPictureFromDB = False
    GoTo procExitFunction
End Function

Public Function SavePictureToDB(RS As ADODB.Recordset, _
    sFileName As String)

    On Error GoTo procNoPicture
    Dim oPict As StdPicture
   
    Set oPict = LoadPicture(sFileName)
   
    'Exit Function if this is NOT a picture file
    If oPict Is Nothing Then
        MsgBox "Invalid Picture File!", vbOKOnly, "Oops!"
        SavePictureToDB = False
        GoTo procExitSub
    End If
   
    RS.AddNew
   

    Set strStream = New ADODB.Stream
    strStream.Type = adTypeBinary
    strStream.Open
    strStream.LoadFromFile sFileName
    RS.Fields("***YourImageField***").Value = strStream.Read
   
    Image1.Picture = LoadPicture(sFileName)
    SavePictureToDB = True
   
   

procExitSub:
    Exit Function
procNoPicture:
    SavePictureToDB = False
    GoTo procExitSub
End Function
0
 

Author Comment

by:catti
ID: 9831246
Hi MyLim!
I've tried your solution, but in the statement
Image1.Picture = LoadPicture("C:\temp.bmp")
i get an error; Invalid picture.
Iv'e checked that the file temp.bmp i created at C: but it's not possible to open it. I get a message that it's not allowed to preview.
What can be the problem?
Thankful for help
/catti
0
 
LVL 1

Expert Comment

by:MsLim
ID: 9834645
thinking
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9834672
Invalid Picture
Only an icon, bitmap, or Windows metafile can be assigned to the Picture property or Picture object.  

You attempted to assign a file to a Picture property or a Picture object that is not recognized as an icon, bitmap, or Microsoft Windows metafile.  For the MouseIcon property, the valid pictures are .ICO and .CUR file types.

1.Please make sure your database have picture store.
2.try open your temp.bmp by some other program like bitmap,internet explorer,imaging and etc...
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9834728
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

by:MYLim
ID: 9835308
actually,i have use Adodc1 control and bind to picture box control with no problem,so
wat is ur problem? any error msg ?
0
 

Author Comment

by:catti
ID: 9835639
Yes! When I start the app I get teh message: Unable to bind to field or data member: "bild". This is the name of my field in the access db. I have declared the field as an ActivX-object and inserted a bitmap file.
/catti
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9835822
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9836009
0
 
LVL 8

Accepted Solution

by:
MYLim earned 125 total points
ID: 9836018
below are demo that i try with no problem,save to form1.frm and modify to suite yourself.

VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   4515
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7260
   LinkTopic       =   "Form1"
   ScaleHeight     =   4515
   ScaleWidth      =   7260
   StartUpPosition =   2  'CenterScreen
   Begin MSAdodcLib.Adodc Adodc1
      Height          =   375
      Left            =   120
      Top             =   3120
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyProgram2\Save Picture Access Image\pictures.mdb;Persist Security Info=False"
      OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyProgram2\Save Picture Access Image\pictures.mdb;Persist Security Info=False"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "Pictures"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command1
      Caption         =   "Get Picture"
      Height          =   495
      Left            =   120
      TabIndex        =   9
      Top             =   1680
      Width           =   1215
   End
   Begin VB.CommandButton CmdLast
      Caption         =   "Last"
      Height          =   375
      Left            =   6000
      TabIndex        =   8
      Top             =   3600
      Width           =   975
   End
   Begin VB.CommandButton CmdFirst
      Caption         =   "First"
      Height          =   375
      Left            =   6000
      TabIndex        =   7
      Top             =   3120
      Width           =   975
   End
   Begin VB.CommandButton CmdPrev
      Caption         =   "Previous"
      Height          =   375
      Left            =   6000
      TabIndex        =   6
      Top             =   2640
      Width           =   975
   End
   Begin VB.CommandButton CmdNext
      Caption         =   "Next"
      Height          =   375
      Left            =   6000
      TabIndex        =   5
      Top             =   2160
      Width           =   975
   End
   Begin VB.CommandButton cmdUpdate
      Caption         =   "Update Record"
      Height          =   855
      Left            =   6000
      TabIndex        =   4
      Top             =   1200
      Width           =   975
   End
   Begin VB.CommandButton cmdNew
      Caption         =   "Add as New Record"
      Height          =   735
      Left            =   6000
      TabIndex        =   3
      Top             =   360
      Width           =   975
   End
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   360
      Width           =   3615
   End
   Begin VB.Image Image2
      Height          =   480
      Left            =   480
      Picture         =   "Form1.frx":0000
      Top             =   2280
      Width           =   480
   End
   Begin VB.Image Image1
      BorderStyle     =   1  'Fixed Single
      Height          =   3255
      Left            =   1440
      Stretch         =   -1  'True
      Top             =   840
      Width           =   3615
   End
   Begin VB.Label Label2
      Caption         =   "Picture (Right Click to Paste)"
      Height          =   735
      Left            =   360
      TabIndex        =   2
      Top             =   840
      Width           =   975
   End
   Begin VB.Label Label1
      AutoSize        =   -1  'True
      Caption         =   "Description :"
      Height          =   195
      Left            =   360
      TabIndex        =   0
      Top             =   450
      Width           =   885
   End
   Begin VB.Menu MenuOPtion
      Caption         =   "OPtion"
      Visible         =   0   'False
      Begin VB.Menu MenuLoad
         Caption         =   "&Load..."
      End
      Begin VB.Menu MenuPaste
         Caption         =   "&Paste"
      End
      Begin VB.Menu MenuClear
         Caption         =   "&Clear"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const DBName = "D:\MyProgram2\Save Picture Access Image\Pictures.mdb"
Private DB As DAO.Database
Private R As DAO.Recordset
Private Changed As Boolean

Dim Cnn As ADODB.Connection
Dim Rs As ADODB.Recordset

Private Sub GetPicture()

    Dim B() As Byte
    Dim PicSize As Long
    Dim F As Integer
       
    On Local Error Resume Next
   
    Screen.MousePointer = vbHourglass
    Err = 0
    PicSize = R.Fields("Picture").FieldSize
    If PicSize = 0& Then
        Screen.MousePointer = vbDefault
        MsgBox "There is no Picture for this record", vbInformation
        Exit Sub
    End If
    Kill "tmp.bmp"
    Err = 0
    F = FreeFile
    Open "tmp.bmp" For Binary Access Write As #F
    ReDim B(PicSize - 1)
    B() = R.Fields("Picture").GetChunk(0, PicSize)
    Put #F, , B()
    Close #F
    Erase B
    Image1.Picture = LoadPicture("tmp.bmp")
    Screen.MousePointer = vbDefault

End Sub


Private Sub AddRecord()

    On Local Error Resume Next

    Const ChunkSize = 16384
    Dim Chunks As Long
    Dim Fragment As Long
    Dim X As Integer
    Dim B() As Byte
    Dim FileSize As Long
    Dim F As Integer

    Screen.MousePointer = vbHourglass
    Err = 0
    SavePicture Image1.Picture, "tmp.bmp"
    If Err <> 0 Then
        Screen.MousePointer = vbDefault
        MsgBox "The Image could not be stored to a temporary file.", vbCritical
        Exit Sub
    End If
   
    FileSize = FileLen("tmp.bmp")
    F = FreeFile
    Open "tmp.bmp" For Binary Access Read As #F
   
    Chunks = FileSize \ ChunkSize
    Fragment = FileSize Mod ChunkSize
    R.AddNew
    R.Fields("Description") = Text1.Text
    ReDim B(Fragment)
    Get #F, , B()
    R.Fields("Picture").AppendChunk B()
    ReDim B(ChunkSize)
    For X = 1 To Chunks
        Get #F, , B()
        R.Fields("Picture").AppendChunk B()
    Next X
    Close #F
    Erase B
    R.Update
    Screen.MousePointer = vbDefault
    If Err <> 0 Then
        MsgBox "The Record could not be captured (" & Err.Description & ")", vbCritical
        Exit Sub
    End If
    R.MoveLast
    Changed = False

End Sub

Private Sub Data1_Reposition()

    MsgBox "Reposition"

End Sub

Private Sub CmdFirst_Click()
    On Local Error Resume Next
   
    Err = 0
    R.MoveFirst
    Text1 = R.Fields("Description")
    If Err <> 0 Then
        Beep
        Exit Sub
    End If
    GetPicture
    Changed = False

End Sub

Private Sub CmdLast_Click()
    On Local Error Resume Next
   
    Err = 0
    R.MoveLast
    Text1 = R.Fields("Description")
    If Err <> 0 Then
        Beep
        Exit Sub
    End If
    GetPicture
    Changed = False

End Sub

Private Sub cmdNew_Click()

    Text1 = Trim$(Text1)
    If Len(Text1) = 0 Then
        MsgBox "You have not entered a Description.", vbCritical
        Exit Sub
    End If
    If Image1.Picture = 0 Then
        MsgBox "You have not inserted a Picture", vbCritical
        Exit Sub
    End If
    AddRecord
   

End Sub

Private Sub CmdNext_Click()

    On Local Error Resume Next

    Err = 0
    R.MoveNext
    Text1 = R.Fields("Description")
    If Err <> 0 Then
        Beep
        Exit Sub
    End If
    GetPicture
    Changed = False

End Sub

Private Sub CmdPrev_Click()

    On Local Error Resume Next
   
    Err = 0
    R.MovePrevious
    Text1 = R.Fields("Description")
    If Err <> 0 Then
        Beep
        Exit Sub
    End If
    GetPicture
    Changed = False
   
End Sub

Private Sub cmdUpdate_Click()

    On Local Error Resume Next
   
    Const ChunkSize = 16384
    Dim Chunks As Long
    Dim Fragment As Long
    Dim X As Integer
    Dim B() As Byte
    Dim FileSize As Long
    Dim F As Integer
   

    R.Edit
    R.Fields("Description") = Text1
    If Changed Then
        R.Fields("Picture") = Null
        Screen.MousePointer = vbHourglass
        Err = 0
        SavePicture Image1.Picture, "tmp.bmp"
        If Err <> 0 Then
            Screen.MousePointer = vbDefault
            MsgBox "The Image could not be stored to a temporary file.", vbCritical
            R.Cancel
            Exit Sub
        End If
   
        FileSize = FileLen("tmp.bmp")
        F = FreeFile
        Open "tmp.bmp" For Binary Access Read As #F
   
        Chunks = FileSize \ ChunkSize
        Fragment = FileSize Mod ChunkSize
        ReDim B(Fragment)
        Get #F, , B()
        R.Fields("Picture").AppendChunk B()
        ReDim B(ChunkSize)
        For X = 1 To Chunks
            Get #F, , B()
            R.Fields("Picture").AppendChunk B()
        Next X
        Close #F
        Erase B
    End If
    R.Update
    Screen.MousePointer = vbDefault
    If Err <> 0 Then
        MsgBox "The Record could not be updated (" & Err.Description & ")", vbCritical
        Exit Sub
    End If
    Changed = False


End Sub

Private Sub Command1_Click()
'On Error GoTo ErrFound
Set Cnn = New ADODB.Connection
Cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBName & ";User Id=admin;Password=;"

Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
Rs.Open "Select * from pictures", Cnn, adOpenStatic, adLockReadOnly

If Rs.EOF = True Then
 MsgBox "Empty Recordset,Connection will be Close"
 Rs.Close
 Set Rs = Nothing

  Cnn.Close
 Set Cnn = Nothing
 
 Exit Sub
End If

Dim i As Integer
i = 0
For i = i To Rs.Fields.Count - 1
Debug.Print i & " " & Rs.Fields(i).Name
Next i

   

'Loop
Rs.MoveFirst
Set Image2.DataSource = Rs
Image2.DataField = "Picture" 'Rs.Fields("Picture").Name

 Rs.Close
 Set Rs = Nothing

  Cnn.Close
 Set Cnn = Nothing
 
 Exit Sub
ErrFound:
MsgBox "Err description : " & Err.Description
If Rs.State = adStateOpen Then
  Rs.Close
  Set Rs = Nothing
End If
 
If Cnn.State = adStateOpen Then
  Cnn.Close
  Set Cnn = Nothing
End If

End Sub

Private Sub form_load()

    On Local Error Resume Next
   
    Set DB = DBEngine.OpenDatabase(DBName, False)
    If Err <> 0 Then
        MsgBox "Could not open Database " & DBName & ". Sorry.", vbCritical
        End
    End If
    Set R = DB.OpenRecordset("Pictures", dbOpenTable)
    If R.RecordCount > 0 Then
        R.MoveFirst
        Text1.Text = R.Fields("Description")
        Changed = False
        GetPicture
    End If

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    On Local Error Resume Next

    R.Close
    DB.Close
    Set R = Nothing
    Set DB = Nothing

End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If (Button And 2) <> 0 Then
        If Clipboard.GetFormat(vbCFBitmap) Or Clipboard.GetFormat(vbCFMetafile) Or Clipboard.GetFormat(vbCFDIB) Then
           MenuPaste.Enabled = True
        Else
            MenuPaste.Enabled = False
        End If
        PopupMenu MenuOPtion
       
    End If
End Sub

Private Sub MenuClear_Click()

    Set Image1.Picture = Nothing

End Sub

Private Sub MenuLoad_Click()

    On Local Error Resume Next

    Dim FName As String

    MsgBox "You would normally show a load dialog box to do this (use MS Common Dialog Control). I'm not doing that because this machine has a VB6 Common Dialog Control instead of VB5's, so it stuffs the project when loaded under VB5. Therefore, I'm just prompting you for the filename", vbInformation
    FName = Trim$(InputBox$("Please enter the filename where the file is located."))
    If Len(FName) = 0 Then Exit Sub
    If Len(Dir$(FName)) = 0 Then
        MsgBox "The file does not exist.", vbCritical
        Exit Sub
    End If
    Err = 0
    Image1.Picture = LoadPicture(FName)
    If Err <> 0 Then
        MsgBox "The file could not be loaded (" & Err.Description & ")", vbCritical
        Exit Sub
    End If
    Changed = True
   
End Sub

Private Sub MenuPaste_Click()

    Dim cf As Long
   
    If Clipboard.GetFormat(vbCFBitmap) Then cf = vbCFBitmap
    If Clipboard.GetFormat(vbCFMetafile) Then cf = vbCFMetafile
    If Clipboard.GetFormat(vbCFDIB) Then cf = vbCFDIB
   
    Image1.Picture = Clipboard.GetData(cf)
    Changed = True

End Sub
0
 

Author Comment

by:catti
ID: 9856420
Hi MYLim!
That's a lot of code! I didn't think it would be so complicated. Thank you for helping.
/catti
0
 
LVL 8

Expert Comment

by:MYLim
ID: 9856431
welcome
q(^ _ ^)p
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now