I now have the code saving the image in the database using the following code for saving and populating the listbox.
Private Sub Command1_Click()
On Error GoTo Command1_Click_Err 'Error Code Inserted: 11/8/2009 5:38:50 PM ----------ERR--
Const sMOD_NAME As String = "frmContEntryNew.cmdAddImage_Click"
''On Error GoTo Error_Handler
Dim mypicture As String
Dim FN As String
Dim filebinary As String
Dim imagename As String
imagename = Text1(0)
With Dlgs
.Filter = "(*.bmp;*.jpg;*.gif;*.dat;*.pcx)| *.bmp;*.jpg;*.gif;*.dat;*.pcx|(*.psd)|*.psd|(*.All files)|*.*"
.ShowOpen
If .fileName = "" Then Exit Sub
mypicture = .fileName
FN = .FileTitle
'Open File And Read as Binary
Open .fileName For Binary Access Read As #1
filebinary = Space(LOF(1))
Get #1, , filebinary
Close #1
Image2.Picture = LoadPicture(.fileName)
'Add File To DB
' code to add the image to the database and refill the listbox
With rspic
.AddNew
!Client = imagename
!Img_name = FN
!Image = filebinary
.Update
End With
Call GetAllFiles
End With
Exit Sub
Command1_Click_Err: 'Error Code Inserted: 11/8/2009 5:38:50 PM ----------ERR--
If Err <> 0 Then
TestProc_Err: 'Error Code Inserted: 2/4/98 9:12:54 p ----------ERR--
If Err <> 0 Then
frmError.ErrMsg "contact entry", "mTestEnd", Erl, Err
End If
End If
End Sub
Private Sub GetAllFiles()
200 On Error Resume Next
'code to load list box
Dim strSetting As String
362 strSetting = Text1(0)
364 SQL = "SELECT Client, Img_name, Image FROM pic "
365 SQL = SQL & "WHERE Client = " & strSetting & " "
370 List1.Clear
372 With rspic
373 If (.RecordCount > 0) Then
374 .MoveFirst
375 While Not .EOF
If !Client = Text1(0) Then
List1.AddItem !Img_name
End If
378 .MoveNext
379 Wend
380 End If
381 End With
End Sub
However i am unable to load the imagebox when i click a item in the listbox, my code is as follows can somebody please tell me where i have gone wrong
Private Sub List1_Click()
Call ViewPic
End Sub
'Sub added to show image when listbox is clicked AJD
Public Sub ViewPic()
'View Pic From DB
Dim OutFile As String
Dim strSql As String
With rspic
If (.RecordCount > 0) Then
.MoveFirst
While Not .EOF
If !Client = Text1(0) And !Img_name = List1.Text Then
Image1.Picture = !Image
End If
.MoveNext
Wend
End If
End With
End Sub