Button dependent on file availability.

S

SirBob

Hi:

Can anyone help with the following:

I wish to place a button on a form which would be used to open a PDF file
that is linked to the record currently displayed in the form. I can place the
button there, but it is always there, irrespective of whether the PDF exists
or not. What I would like to achieve is to only display the button on the
form if the PDF file exists, should it not exist then to not display the
button.

Thanks
 
D

Daniel

Using the following code (originally written by Doug Steele, Microsoft Access
MVP )

Assuming strMyFileName contains the full path to the file, try the
following:

If Len(Dir$(strMyFileName)) > 0 Then
' strMyFileName exists
Else
' strMyFileName does not exist
End If

You can then control the visibility or enabled property for your control.

Something like
Dim strMyFileName as string
strMyFileName = "c:\windows\desktop.ini"

If Len(Dir$(strMyFileName)) > 0 Then
' strMyFileName exists
Me.ControlName.Visible = True
Else
' strMyFileName does not exist
Me.ControlName.Visible = False
End If

Hope this helps,

Daniel
 
J

John Vinson

Hi:

Can anyone help with the following:

I wish to place a button on a form which would be used to open a PDF file
that is linked to the record currently displayed in the form. I can place the
button there, but it is always there, irrespective of whether the PDF exists
or not. What I would like to achieve is to only display the button on the
form if the PDF file exists, should it not exist then to not display the
button.

Thanks

I'd suggest using code in the Form's Current event. The code could use
the Dir() function to determine whether the file exists on disk, and
set the Visible property of the command button appropriately.

John W. Vinson[MVP]
 
Top