Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 10 votes, 5.00 average. Display Modes
Old 01-01-2009, 12:11 AM   #1
Splinters
Registered User
 
Join Date: Sep 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Splinters is on a distinguished road
VB Dir function - not working?

I have a form with 2 objects:

Text48 - A text box object which will have either a path to an image file, or a dummy path ("c:\BowlPhotos\Thumbs\tmb.jpg").

Image58 - An Image Object with an empty Picture field that is filled by the VB.

The Text48 value is determined by the value of another text box, generated using an equation that works (so I left it out to avoid confusion).

The intent is to bring up the record and, if a product exists AND an image exists, show the image for that record. Otherwise, show the default "no image" jpg.

I am using the following 2 VB functions:
=============================
Private Sub Form_Current()
On Error Resume Next

If Me.Text48.Value = "c:\BowlPhotos\Thumbs\tmb.jpg" Then
Me.Image58.Picture = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
Else
If Dir(Me.Text48.Value) Then
Me.Image58.Picture = Me.Text48.Value
Else
Me.Image58.Picture = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
End If
End If

End Sub
-------------------------------------------
Private Sub Form_Load()
On Error Resume Next

If Me.Text48.Value = "c:\BowlPhotos\Thumbs\tmb.jpg" Then
Me.Image58.Picture = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
Else
If Dir(Me.Text48.Value) Then
Me.Image58.Picture = Me.Text48.Value
Else
Me.Image58.Picture = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
End If
End If

End Sub
===============================

There are 3 possible conditions:

1: No product exists. The default text in Text48 is the "NoBowltmb.jpg" path - so the result should show the "NoBowltmb.jpg" image, which it does.

2: A product does exist, and there is an image of it. The text in Text48 is the generated path to that image, and the image does exist - so the result should show the bowl image, which it DOES do.

3: A product does exist, but there is no image of it yet. The text in Text48 is the generated path to that bowl's image, but the image does not yet exist - so the result should show the "NoBowltmb.jpg" image, which it does NOT always do. What it does instead is retain the previous image for the previous record.

Example: If the previous record was for bowl Ash08-021, and the image exists (and was shown for THAT record), the Ash08-021 image shows up in the NEXT record IF there is no image for THAT NEW record. IF, on the other hand, the previous record was also a no image case (and showed the default image), it shows the default NoBowltmb.jpg" image. Of course, if the prior record showed an image from IT'S prior record, that image shows up! Sort of a self replicating error...

Case 3 is the problem - I need it to show either the current selected bowl's image (if it exists) or the default no image (if the image does not exist).

I had hoped that the "Dir" function in the inner If segment would determine if the image existed, and take the appropriate action. It does not seem to do this.

Any ideas?

Splinters is offline   Reply With Quote
Old 01-01-2009, 05:12 AM   #2
Fuse3k
Newly Registered User
 
Join Date: Oct 2007
Posts: 74
Thanks: 6
Thanked 5 Times in 5 Posts
Fuse3k is on a distinguished road
Re: VB Dir function - not working?

Try:

Code:
If Not Dir(Me.Text48.Value, vbDirectory) = vbNullString Then
   'pathfound
Else
   'pathnotfound
End if
Fuse3k is offline   Reply With Quote
Old 01-01-2009, 12:21 PM   #3
Splinters
Registered User
 
Join Date: Sep 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Splinters is on a distinguished road
Re: VB Dir function - not working?

Quote:
Originally Posted by Fuse3k View Post
Try:

Code:
If Not Dir(Me.Text48.Value, vbDirectory) = vbNullString Then
   'pathfound
Else
   'pathnotfound
End if
OK, that helped.

I tried the following:
[code]
Dim nullStr As String
Dim defaultStr As String
Dim currStr As String

nullStr = "c:\BowlPhotos\Thumbs\tmb.jpg"
defaultStr = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
currStr = Me.Text48.Value

Me.Image58.Picture = nullStr

If Not Dir(currStr, vbDirectory) = currStr Then
Me.Image58.Picture = currStr
Else
Me.Image58.Picture = defaultStr
End If
[end code]

That works - in that it gives the null image both when there is no product, AND when there is a product but no image - but provides the proper image when one exists.

But the else code does not seem to work, since it does not show the default "No Image" image when a product exists and there is no existing image...

This will suffice for now - but I would like to know why the else code does not seem to work...

Thanks

Splinters is offline   Reply With Quote
Old 01-01-2009, 12:41 PM   #4
Splinters
Registered User
 
Join Date: Sep 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Splinters is on a distinguished road
Re: VB Dir function - not working?

After looking at this a bit more, I realized it could be done easier.

[code]
Dim defaultStr As String
Dim currStr As String

defaultStr = "C:\BowlPhotos\Thumbs\NoBowltmb.jpg"
currStr = Me.Text48.Value

Me.Image58.Picture = defaultStr

If Not Dir(currStr, vbDirectory) = currStr Then
Me.Image58.Picture = currStr
End If
[end code]

"C:\BowlPhotos\Thumbs\NoBowltmb.jpg" has text saying there is no image found.

Then I used that to make a blank image of the same size for "C:\BowlPhotos\Thumbs\tmb.jpg", the path when there is no product.

This gives me the 3 possibilities I needed.

Thanks for the help.
Splinters is offline   Reply With Quote
Old 01-08-2009, 02:29 PM   #5
doco
Power User
 
doco's Avatar
 
Join Date: Feb 2007
Location: E.Oregon, USA
Posts: 471
Thanks: 23
Thanked 4 Times in 3 Posts
doco is on a distinguished road
Re: VB Dir function - not working?

Having similar problem with using Me.Image111.Picture = szPath throwing an error 'cannot open, etc' Is there some special magic associated with using a string variable for the path instead of a hard coded path? I have tried putting CHR(34) before and aft but nothing works accept hard coding the actual path and that is absurd.

TIA
__________________
Consensus is the lack of leadership
doco is offline   Reply With Quote
Old 01-08-2009, 02:39 PM   #6
doco
Power User
 
doco's Avatar
 
Join Date: Feb 2007
Location: E.Oregon, USA
Posts: 471
Thanks: 23
Thanked 4 Times in 3 Posts
doco is on a distinguished road
Re: VB Dir function - not working?

I got it. Evidently the textbox is passing some leading and or trailing spaces. So

Code:
...
    Me.Image111.Picture = TRIM$(szPath)
...
does the trick.
__________________
Consensus is the lack of leadership
doco is offline   Reply With Quote
Old 01-08-2009, 07:43 PM   #7
Splinters
Registered User
 
Join Date: Sep 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Splinters is on a distinguished road
Re: VB Dir function - not working?

Quote:
Originally Posted by doco View Post
I got it. Evidently the textbox is passing some leading and or trailing spaces. So

Code:
...
    Me.Image111.Picture = TRIM$(szPath)
...
does the trick.
Interesting...mine seems to work without the trim. Not being an "expert" on Access - not in the slightest - I can't say why your solution is different. Using a string var should act the same in both cases...My best guess is that our text boxes may be set up slightly different. Is there a default string in your text box that might have included the spaces?

Splinters is offline   Reply With Quote
Old 01-08-2009, 08:02 PM   #8
doco
Power User
 
doco's Avatar
 
Join Date: Feb 2007
Location: E.Oregon, USA
Posts: 471
Thanks: 23
Thanked 4 Times in 3 Posts
doco is on a distinguished road
Re: VB Dir function - not working?

I am reading in this case, a field from an Access table that is of hyperlink data type. If you view the rs.Fields("MyField").Value from a hyperlink type you will see it has a '#' attached the beginning and ending of the actual path string. Therefore, I had to use code to strip the leading and trailing '#'. There should not have been any leading and trailing spaces but evidently there are. So, The TRIM$(string) function was being used.

I am at home now but will post the code when I get to the office tomorrow if interested.

__________________
Consensus is the lack of leadership
doco is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How many users opening a BE .mdb? FuzMic Modules & VBA 10 07-25-2008 12:53 AM
VB for MsAccess 2000 How to pass name of object to function LostUser Forms 7 05-16-2008 08:57 AM
+ 7 Working Days Date Function JPW Modules & VBA 41 04-06-2008 04:11 PM
Database Update Randomblink Modules & VBA 6 02-16-2004 08:24 AM
IsOpen Function not Working grayth Forms 1 06-02-2001 05:50 AM




All times are GMT -8. The time now is 10:11 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World