Prevent form from opening

jmeek

Registered User.
Local time
Today, 02:35
Joined
Aug 16, 2005
Messages
38
I need to prevent a form from opening if
no data (no picture) is found in an image
control on the form that needs to be
opened.
The form is opened in this manner:

DoCmd OpenForm StDocName,,,stLinkCriteria

Certain records will not have a picture so the
form doesn't need to be opended.

Thank you
 
Code:
IF DCOUNT("[keyfield","table",strLinkCriteria) > 0 Then
     DoCmd OpenForm StDocName,,,stLinkCriteria
Else
     MsgBox "No matching Records", vbOkOnly
End If
 
Hi ScottGem

Thanks for your example but the problem is
that the picture is not embeded. The field in
the table refers to the jpg such as c:\pictures\123.jpg.
Therefore the form will still open. The code or your example
needs to checks for the existence of the file itself.
Can that be done.

Thanks
 
Searching the forum is a great way to discover and learn the answers to your questions.

Use the Dir() function.

Code:
If Dir("c:\pictures\123.jpg") = "" Then
    MsgBox "picture does not exist"
Else
    MsgBox "picture does exist"
End If
 
ScottGem

The DIR function still doesn't prevent the form
from opening. Just tells you whether the file
exists or not.
However, if i wanted to tie it in with stLinkCriteria
as stated above on the initiating form how would I
compare the jpg on disk to the name in the field.

So, the record on the form has a product code of ABC123
The path to the file in the fldPath is "c:\pics\ABC123.jpg"
When I click the button "Picture", the form will open with
the jpg ABC123.jpg. If there is no file on disk the form
should not open.

Thanks again.
 
jmeek said:
ScottGem
The DIR function still doesn't prevent the form
from opening. Just tells you whether the file
exists or not.

Exactly! You need to think thru the logic here. You want to see if the file exists. If it does you open the form, if it doesn't you show a message.

So all you need to do is change the code I gave you to use the DIR command.
 
Can anybody help on the following matter

Have a form(1) that opens another form(2) that has an image
control on it. The path to the image is held in a field in a
table. The image file itself may or may not exist on the
hard disk but the full path and the name of the file is held
in the table.
I don't want form(2) to open at all if the image file doesn't exist
on the hard disk.

As you can see a couple of suggestions have been posted but
they do not work. Would work if the path and file name didn't
exist in the table.

Many thanks
 
Why don't they work? I've used similar code in other apps and it works fine.
 

Users who are viewing this thread

Back
Top Bottom