Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding photo`s in my VB Database

Status
Not open for further replies.

1x2z3

Programmer
Sep 18, 2003
39
ZA

1. I have a picture control in my VB application.
2. I created a OLE object in Access that holds the picture.
3. I insert the picture in access and save it.
4. If I try to view and safe pictures in VB it don’t want to safe the picture or view it.
5. Can I maybe assign a Path to each photo that I want to view in the database without saving the actual photo.
6. Please help with the correct code to use.

Here is the coding I used :
______________________________________________________
General Declaration

Dim cn As ADODB.Connection 'Connect to a Database.
Public rs As ADODB.Recordset 'Set records.
_______________________________________________________

Private Sub Picture1_Click()

Dim strFileName As String 'String of file to open
Dim strText As String 'Contents of file
Dim strFilter As String 'Common Dialog filter string
Dim strBuffer As String 'String buffer variable
Dim FileHandle% 'Variable to hold file handle

'Set the Common Dialog filter
strFilter = "Graphics (*.BMP)|*.BMP|Graphics (*.JPG)|*.JPG|Graphics (*.TIF)|*.TIF|Graphics (*.WMF)|*.WMF|Graphics (*.GFX)|*.GFX|All Files (*.*)|*.*"
cdMain.Filter = strFilter

'Open the common dialog
cdMain.ShowOpen

'Make sure the retrieved filename is not a blank string
If cdMain.FileName <> &quot;&quot; Then

'If it is not blank open the file
strFileName = cdMain.FileName

'Get a free file handle and assign it to the file handle variable
FileHandle% = FreeFile

'Open the file
Open strFileName For Input As #FileHandle%

’Make the mouse cursor an hourglass
MousePointer = vbHourglass

'Traverse the lines of the file
Do While Not EOF(FileHandle%) ' Check for end of file.

'Read a line of the file
Line Input #FileHandle%, strBuffer ' Read line of data.

'Add the line from the output buffer to the text string
strText = strText & strBuffer & vbCrLf
Loop

'Change the mousepointer back to the arrow
MousePointer = vbDefault

'Close the file once you have had your way with it
Close #FileHandle%

End If
_______________________________________________________

Private Sub cmdSave_Click()

rs!Picture = Picture1.Picture & &quot;&quot;
________________________________________________________

Public Sub PopulateControls()

Picture1.Picture = rs!Photo & &quot;&quot;
_________________________________________________________

 

1x2z3, have you read FAQ222-2244 item 15 yet?

>5. Can I maybe assign a Path to each photo that I want to view in the database without saving the actual photo.

Yes, you can do that, you would need a string field (text or memo), and from the looks of it you have most of the code that you need except for the LoadPicture function of which you can look up in the help files.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top