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!

How to save a Path of an Image in a database...

Status
Not open for further replies.

1x2z3

Programmer
Sep 18, 2003
39
ZA
How can I safe the path for my graphic file that I loaded into my Image Control

1. I have a Image Control, Text Box & Common Dialog in my database form.
2. I Open the file where the pictures is saved, via the Common Dialog Control.
3. The picture is loaded into the Image Control when I click on it.
4. I saved the picture at run time into my textbox, it gives me a nr & not the actual file name and the picture is visible in the Image control .
5. I want to link the path of the picture from the text box to the image control.
6. I want to view the actual picture that I saved at Run Time in the text box.
7. The number of the picture is in the textbox at run time but the picture is not shown in the image control at run time when I restart the project.
8. How can I link the path : textbox to the picture of the picture control.
9. I don’t want to save the actual pictures in the database but just it’s deferent paths in the textbox..
10. If I go into separate data records it must show me the actual pictures which paths I saved in the textbox.


HERE IS THE CODE THAT I USED :

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

_________________________________________________________

Public Sub OpenConnection()

'Database to be opened.
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\VB\CMS\CMS.mdb"
cn.Open

End Sub

_________________________________________________________

Public Sub ReturnRecords()

'Records to be set.
Set rs = New ADODB.Recordset

OpenConnection

rs.ActiveConnection = cn
rs.Source = "SELECT * FROM [Detainee Particulars] ORDER BY Surname"
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Open

End Sub

_________________________________________________________

Private Sub cmdSave_Click()

rs!Photo = txtPath.Text & ""

End Sub

_________________________________________________________

I THINK MY PROBLEM IS HERE : AT RUN TIME

PopulateControls

ComDiaPhoto.FileName = rs!Photo & ""
txtPath.Text = rs!Photo & ""
If ComDiaPhoto.FileName <> &quot;&quot; Then
ImgPhoto.Picture = LoadPicture(ComDiaPhoto.FileName)
End If

End if


















 

1x2z3, have you read FAQ222-2244 yet?

There are a couple of things that I do not see in your code but I will take for granted.

Now under your save button you have set the photo field to the value of the contents of the text box but I do not see where you update the record (rs.Update) which may be your problem, because when you move to the next record the rs will discard any changes because you do not have an update statement anywhere.

Good Luck

 
In addition, I can not see why the ComDiaPhoto is being used to reload.

First, as vb5prgrmr suggests, make sure that the path actually was saved.


Msgbox rs!Photo & &quot;&quot;
'should do it - should also error trap for null..

then, try this:

if dir(rs!Photo & &quot;&quot;) > &quot;&quot; then
ImgPhoto.Picture = LoadPicture(rs!Photo & &quot;&quot;)
endif

 
Sorry vb5prgrmr i actually use the update in my save command i forgot to show it in the code when i send it

Private Sub cmdSave_Click()

rs!Photo = txtPath.Text & &quot;&quot;

End Sub


JefTullen it seems that the path was saved in the text box cause it only displays the number of the graphic i entered.
I`ll try the coding you gave me and see what happens.

thanks to you all...
 
JeffTillun : I tried your code; the image is acctually saved. If I for instance select a cat graphic, it shows in the message box the following number. -23876878. My Image contol is updated when the save cmdButton is selected, But the ImageControl itself doesn`t update with the rs!Photo that`s being saved in the database. All the graphics i select and safe is saved as a sort of code as mentioned above. Do you have any other surgestions for me please...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top