Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

RUSH >>> Loading picture

Posted on 2004-09-24
8
209 Views
Last Modified: 2010-05-02
why does the picture doesnt load, pls debug my code, what is stored in tblAdv_FileName field in my database is just a link to the picture (like c:/proj1/images/pic1.jpg). this code of mine is stored in the Form_Load() event.

Dim conn As New ADODB.Connection
Set conn = New ADODB.Connection
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset

conn.CursorLocation = adUseClient
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
& "DATABASE=BHMTC;" _
& "UID=root;" _
& "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384

conn.Open

rs.Open "SELECT * FROM tblAdv", conn, adOpenStatic, adLockOptimistic

Picture1.Picture = LoadPicture(rs.Fields(tblAdv_FileName))

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
0
Comment
Question by:justin_316_sr
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12141448
add this line

Debug.Print rs.Fields(tblAdv_FileName)

to see what value did you get from DB
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12141458
Offtopic, this

Dim conn As New ADODB.Connection
Set conn = New ADODB.Connection
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset

change to

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 12141467
Also, you should use Set when loading picture

Set Picture1.Picture = LoadPicture(rs.Fields(tblAdv_FileName).Value)

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 10

Assisted Solution

by:anv
anv earned 20 total points
ID: 12141490
Before u execute the statement

Picture1.Picture = LoadPicture(rs.Fields(tblAdv_FileName))

make sure the File stored in the Field name "tblAdv_FileName" exists on the hard drive

U Need to check the whole path of the file or image u want to load..

if u r storing the whole path of the file in ur database then only it will display image..else not..

in ur othet question, i feel u r only storing the file name and not the filepath..

try to store the file name using commondialog1.FileName

0
 

Author Comment

by:justin_316_sr
ID: 12141518
@mladenovicz
there's an error, (item cannot be found in the collection corresponding to the requested name or ordinal) on the debug line you suggested, i added it before the set picture1.picture line

@anv
i already stored the filename & its path on my db, i just need to output it on the picture control
0
 
LVL 10

Expert Comment

by:anv
ID: 12141552
check the field name ur giving in the code with the database

use this instead rs!tblAdv_FileName  where tblAdv_FileName is the field name as given in the database
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 480 total points
ID: 12141557
Set Picture1.Picture = LoadPicture(rs.Fields("tblAdv_FileName").Value)
0
 

Author Comment

by:justin_316_sr
ID: 12141603
@mladenovicz

arrgghh! so thats what i forgot! hahaha, this programming just takes soooo much from me... maybe i'll just rest for a while and maintain my "sanity" hahaha

tnx, points awarded
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question