{RESOLVED} Displaying Pictures From A File Path Stored In A Database
Hey, I am using an ADO control to display records from my database and I want pictures to be shown to from a field in the same table, it has the pat hto the picture, I am using an image control to show them, when the form is loaded I am trying to get it too display the current record picture, here is my code
VB Code:
Private Sub Form_Load()
browseConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Rob\Desktop\VB\contacts.mdb"
browseConn.Open
browseRecc.Open "SELECT * from Contacts WHERE Name='" & lblName.Caption & "'", browseConn, adOpenDynamic, adLockOptimistic
imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
End Sub
And then when I run it, it says 'File could not be found & browseRecc() &'
can someone please help ?
Re: Displaying Pictures From A File Path Stored In A Database
Quote:
Originally Posted by robcarr2
Hey, I am using an ADO control to display records from my database and I want pictures to be shown to from a field in the same table, it has the pat hto the picture, I am using an image control to show them, when the form is loaded I am trying to get it too display the current record picture, here is my code
VB Code:
Private Sub Form_Load()
browseConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Rob\Desktop\VB\contacts.mdb"
browseConn.Open
browseRecc.Open "SELECT * from Contacts WHERE Name='" & lblName.Caption & "'", browseConn, adOpenDynamic, adLockOptimistic
imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
End Sub
And then when I run it, it says 'File could not be found & browseRecc() &'
can someone please help ?
Shouldn't
VB Code:
imgAvatar.Picture = LoadPicture(" & browseRecc(" & avatar & ") & ")
be
VB Code:
imgAvatar.Picture = LoadPicture("" & browseRecc("" & avatar & "") & "")
or something along those lines ?
Re: Displaying Pictures From A File Path Stored In A Database
Hi,
'Assumes complete file path and filename are in the field: Avatar
'like: C:\pictures\mypic.jpg
imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))
OR
'if picture files are in your application's folder you can use:
imgAvatar.Picture = LoadPicture(App.Path & "\" & browseRecc.fields("avatar"))
OR
'Hardcoding the path.
imgAvatar.Picture = LoadPicture("C:\" & browseRecc.fields("avatar"))
Have a good one!
BK
Re: Displaying Pictures From A File Path Stored In A Database
Well, first off :
1) Are you returning records for your SQL statement? How many?
2) I do not see avatar declared or any value assigned to avatar for that matter? Maybe I am not reading your syntax right. Is avatar a string or a field?
Re: Displaying Pictures From A File Path Stored In A Database
Quote:
Originally Posted by Black__Knight
Hi,
'Assumes complete file path and filename are in the field: Avatar
'like: C:\pictures\mypic.jpg
imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))
OR
'if picture files are in your application's folder you can use:
imgAvatar.Picture = LoadPicture(App.Path & "\" & browseRecc.fields("avatar"))
OR
'Hardcoding the path.
imgAvatar.Picture = LoadPicture("C:\" & browseRecc.fields("avatar"))
Have a good one!
BK
just tried
VB Code:
imgAvatar.Picture = LoadPicture(browseRecc.fields("avatar"))
but it came up with an erorr saying Type Mismatch
Re: Displaying Pictures From A File Path Stored In A Database
Hi,
Is your field: Avatar a text field? LIke JLester asked are you sure you are returning a record(s)?
You can also try for testing purposes to remove the WHERE clause and return all records and see if the first picture is loaded. If not then the problem is with your WHERE clause and it isn't finding a matching record.
'Place this line before your LoadPicture statement to make sure the path and filename are correct.
Debug.Print browserecc.fields("Avatar")
Have a good one!
BK
Re: Displaying Pictures From A File Path Stored In A Database
i have fixed it now, thanks for the code black knight :)