|
-
Jun 3rd, 2005, 01:36 PM
#1
Thread Starter
Hyperactive Member
{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 ?
Last edited by robcarr2; Jun 3rd, 2005 at 02:27 PM.
-
Jun 3rd, 2005, 01:40 PM
#2
Re: Displaying Pictures From A File Path Stored In A Database
 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 ?
-
Jun 3rd, 2005, 01:42 PM
#3
Addicted Member
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
-
Jun 3rd, 2005, 01:44 PM
#4
Junior Member
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?
-
Jun 3rd, 2005, 01:58 PM
#5
Thread Starter
Hyperactive Member
Re: Displaying Pictures From A File Path Stored In A Database
 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
-
Jun 3rd, 2005, 02:04 PM
#6
Addicted Member
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
Last edited by Black__Knight; Jun 3rd, 2005 at 02:10 PM.
-
Jun 3rd, 2005, 02:26 PM
#7
Thread Starter
Hyperactive Member
Re: Displaying Pictures From A File Path Stored In A Database
i have fixed it now, thanks for the code black knight
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|