Picture Path working but not what I want...

G

Gina Whipp

Hi All,

I inherited a database which I am fixing (like field names) but my main
problem is... The code works but you HAVE to store the image in .bmp
format. What I would like is whether the picture is '.jpg' or '.png' or
'.bmp' for it to be able to show. How do I code a dynamin? file extension?
I am at a loss.

Thanks for any and all help!

****CODE START****
imgSketch.Picture = ""

Dim PicPath, PNum, FormNum As String
Dim Length As Integer
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'rtw 2.7.2006 rem out this Exit Sub not working
'If IsNull(PNum = Text558.Value) Then
'Exit Sub
'Else
PNum = Text558.Value
'End If

If Not IsNull(Combo573.Value) Then
FormNum = Combo573.Value
End If

'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection

'Create an instance of the ADO Recordset class, and set its properties
Set rs = New ADODB.Recordset

With rs
Set .ActiveConnection = cn
.Source = "SELECT tblPath.Path FROM tblPath"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With

Length = Len(rs("Path"))
If Mid(rs("Path"), Length - 1, 1) = "/" Then
PicPath = rs("Path") & PNum & FormNum & "-1.bmp"
Else
PicPath = rs("Path") & "\" & PNum & FormNum & "-1.bmp"
End If

On Error Resume Next
imgSketch.Picture = PicPath


Set rs = Nothing
Set cn = Nothing
End Sub
****CODE END****
 
C

Carl Rapson

Add a combo box to your form for the file extension (let's say it's called
Combo559). Set the RowSourceType property of Combo559 to Value List, and put
the allowable file extensions in the RowSource property:

"BMP";"JPG";"PNG"

Of course, you'll also need to test to make sure Combo559 isn't blank (like
you do with Text558). Then use it as follows:

PicPath = rs("Path") & PNum & FormNum & "-1." & Combo559.Value

HTH,

Carl Rapson
 
G

Gina Whipp

Won't work... These people just drop the image in a the folder. They have
no clue what the extension is. What I wanted to do is find a way for it not
to care what file extension it was as long as it's an image and just display
it. (I hope that made sense).
 
J

John Spencer

OUCH, so it's possible they could put
Handsome.png, Handsome.jpg, and Handsome.bmp
in the folder.

The only way I could think to handle something like this would be to check
the folder for each extension and grab the first one that I find

Dim strPath as string
strPath =rs("Path") & PNum & FormNum & "-1."

IF Len(Dir(strPath & "bmp")) > 0 then

ElseIf Len(Dir(StrPath& "png")) > 0 then

ElseIF ...

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Gina Whipp

Wheres there's a will there's a way...

John, that just might work, at least it gives me a direction to start in...
THANKS!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top