Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 21st, 2010, 08:18 AM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Question Open an external jpg with a button

Hi

My status:
Im a beginer in the access vba langue and as all beginers i thaugt something that turned out to be realy complicated to be an easy task.

Baground info (skipable):
Im working on an database over pictures for archivation and have been working on it a couple of years. And over the cristmas weeked some bigshot desided it would be good to have a thumbnail on eatch picture in the database (since they are in .jpg thumbnail isent possible but links are true ole pakages, that they found out for them self before dumping it on our laps). Did an ecourse on access and it explained how to make personalised letters with info taken from a database. And thats where i got the idea but after getting toons of books and 1 week of trying im still non the wiser

The Problem:
The trouble with ole pakages are they arent auto updating and you have to enter them for eatch new post. (Kind of a pain since its alredy over 5.000 posts that needs to be updated and another 1.000 in an papperclip base)

What i would like:
A cmdButton that opens a coresponding filename to a field in the database.
For example "field name": A00001, A00002, A00003... opens A00001.jpg A00002.jpg A00003.jpg... (not in access but on the asigned program on the computer for .jpg files) or a way of making the ole objekt to auto update the pakages for eatch post

greatfull for any help at all
Andreas
Reply With Quote
  #2 (permalink)  
Old January 22nd, 2010, 09:05 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Hi and welcome to Wrox!

It's never a good idea to store photos inside the database, so asking to link them from a directory is a smart move on your part.

Thumbnail or not, you can merely put an image object on your form, size it small. Set its Size Mode property to Zoom.

On the button's ON CLICK event, you'd just assign the photo depending on the file name stored in your fields.

For example

Me.imgThumb = Me.txtFilePath & "\" & Me.txtFileName & ".jpg"

If your path and name were instead calculated string variables based on something else,

Me.imgThumb = strFilePath & "\" & strFileName & ".jpg"
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
Reply With Quote
The Following User Says Thank You to SerranoG For This Useful Post:
Anduz (January 29th, 2010)
  #3 (permalink)  
Old January 29th, 2010, 09:55 AM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi
Thanks for your reply, wish i was as fast noticing it + im an expert on putting thing up :(

I under stand the "Me.imgThumb = strFilePath & "\" & strFileName & ".jpg""

Is it like somthing?:

Private Sub cmdTestbuton_Click()
Dim strFilePath As String
Dim strFileName As Field

strFileName = Lopnr & ".jpg" 'Lopnr is the field name where the filename is stored a number in this case
stFilePath = "c:\testobj"

Me.imgThumb = strFilePath & "\" & strFileName & ".jpg"

But i dont understand the variable for "Me.imgThumb" exept the ME part that means the curent form rigth?

Last edited by Anduz; January 29th, 2010 at 10:01 AM..
Reply With Quote
  #4 (permalink)  
Old January 29th, 2010, 10:21 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

It's more like.

Dim strFileName as String (not Field)
strFileName = Me.Lopnr & ".jpg"

Yes, the "Me" in Me.imgThumb is the active form. imgThumb is an image control placed on your form. What you're doing is leaving it unbound in design view. Then on the fly, you're assigning it to the photo located in strFilePath & strFileName.
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
Reply With Quote
The Following User Says Thank You to SerranoG For This Useful Post:
Anduz (January 29th, 2010)
  #5 (permalink)  
Old January 29th, 2010, 11:44 AM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi again
Tried a few difrent objekts (grafic, bound and unbound ole objekt) as imgThumb I only get runtime error 438 objekt dosent support the property or method. I now i do something wrong (exept speling like a 3 year old as a friend pointed out) what objekt class should i assign as Img control and how do i "leaving it unbound in design view".
Reply With Quote
  #6 (permalink)  
Old January 29th, 2010, 11:53 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

The object type should be image, not bound or unbound object frame (OLE). To leave it unbound in the design view, you do not assign a file name in its Picture property in design view. You assign it later in your code.

Oh, my apologies. I missed the correct syntax. It is:

Me.imgThumb.Picture = strFilePath & "\" & strFileName & ".jpg"

or if strFilePath already has the last "\" in it and strFileName already has ".jpg" in it, then it's simply:

Me.imgThumb.Picture = strFilePath & strFileName
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
Reply With Quote
The Following User Says Thank You to SerranoG For This Useful Post:
Anduz (January 29th, 2010)
  #7 (permalink)  
Old January 29th, 2010, 12:46 PM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Yes it works you are awsome man :D
Reply With Quote
  #8 (permalink)  
Old January 30th, 2010, 07:56 AM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi again
I continue in this tread tho it address the same problem. The thumbnails is great and this is suggar on top but...
This time i actualy stumbled on how to open an external app in the button wizzard, when i tryied to make next post, new post and so on to tie the updating of the thumbnail to them.

And i almost got it to work.

Private Sub OpenPic_Click()
'On Error GoTo Err_OpenPic_Click

Dim strFileName As String
Dim strFilePath As String
Dim stAppName As String

strFilePath = "\testpics\"
strFileName = Me.Lopnr & ".jpg"
stAppName = "C:\Windows\system32\mspaint.exe"
Call Shell(stAppName & strFilePath & strFileName, 3)

Exit_OpenPic_Click:
Exit Sub

Err_OpenPic_Click:
MsgBox Err.Description
Resume Exit_OpenPic_Click

End Sub

This will open "paint" and load the current pic from the database.
The problem is i cant make it read the file path:

Call Shell(stAppName & strFileName, 3) 'Works if i put the picture in C:\*.jpg

OR

stAppName = "C:\Windows\system32\mspaint.exe \testpic\"
Call Shell(stAppName & strFileName, 3) ' Also works then it opens C:\testpic\*.jpg


or accept any other dir than C: if it for example put:

"strFilePath = D:\testpic\" it read out C:\D:\testpic\

this make a problem tho the database and pictures are stored on an external drive for bakup reasons.
Reply With Quote
  #9 (permalink)  
Old January 30th, 2010, 08:11 AM
Registered User
 
Join Date: Jan 2010
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Solved it :D
Call Shell(stAppName & strFilePath & strFileName, 3) Print out:
C:\Windows\system32\mspaint.exed:\testbilder\1.jpg

Call Shell(stAppName & " " & strFilePath & strFileName, 3) Print out:
C:\Windows\system32\mspaint.exe d:\testbilder\1.jpg
And it works
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a button image to open an alert? larry Javascript How-To 2 June 30th, 2007 09:32 AM
how to open new window on button click nittin14 ASP.NET 1.0 and 1.1 Basics 8 April 28th, 2007 12:13 AM
Open a new window on a button click ag19702004 .NET Framework 2.0 1 January 6th, 2007 12:21 AM
Open external DB in MS Access VB problem Derek_05 Access VBA 1 January 21st, 2006 03:51 AM
how do i open an external application from VB6? cipher_nb VB How-To 3 December 20th, 2004 11:04 AM



All times are GMT -4. The time now is 11:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.