Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable button if \\share\folder\file exists 1

Status
Not open for further replies.

Emblem1

Technical User
Jan 11, 2007
77
US
On a form, if I have a record with a serial number of 123456789 (in a textbox called Serial_Number), I want to search inside \\share\folder\ to find a file with the same name as the serial number, with a pdf extension, eg 123456789.pdf. If it exists, show a command button to open the file. If not, then I want to hide (not visible) the button.

Furthermore, I want to display a pointer that shows it working to open the file (pointer/hourglass combo) until the file is opened.

I have played around with populating a list box if the file is there, which works, but I can't get it to show (or not) the button if the list box is null (or not).

But there has to be an easier way than using a hidden form control like the list box, just to show/hide another form control.

Thnaks in advance.

Thanks.
 
You may consider the FileSearch object (unless you're playing with ac2007) and the FollowHyperlink method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Something like:
Code:
MyCommandButton.Visible = Len(Dir("\\share\folder\ " & MyTextBox.Value & ".pdf"))
Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
PHV said:
FileSearch object (unless you're playing with ac2007)
I've almost finished a FileSearch variant that can be used with Access 2007 (not had much time to work on it recently)... [wink]

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Thanks!

Here is what what works...


cmdOpenTestReport.Visible = Len(Dir("\\s02\s02usr\Traffic Signal Monitor Reports\" & z))

However, when Acrobat reader opens to show the file, it opens up in the back. How can I be sure that it opens it up to the front of other windows..?

Oh, and I am using Access 2003.
 
How are you opening the file?

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Like this:

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10

Private Sub RunShellExecute(sTopic As String, _
sFile As Variant, _
sParams As Variant, _
sDirectory As Variant, _
nShowCmd As Long)

Dim hWndDesk As Long
Dim success As Long

'the desktop will be the
'default for error messages
hWndDesk = Application.hWndAccessApp

'execute the passed operation
success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)

'This is optional. Uncomment the three lines
'below to have the "Open With.." dialog appear
'when the ShellExecute API call fails
If success < 32 Then
Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
End If

End Sub

Private Sub Combo20_AfterUpdate()

z = "" 'coding needed for report opening...

If IsNull(Me.Combo20) And a1 = "3" Then
Call clean_blank
End If


Me.add_record.Visible = True

a1 = "1"

Call verify_serialnumber

Me.FileList.RowSource = ""

Call ListFiles("\\s02\s02usr\Traffic Signal Monitor Reports\", z, , Me.FileList)

cmdOpenTestReport.Visible = Len(Dir("\\s02\s02usr\Traffic Signal Monitor Reports\" & z))

End Sub


Private Sub cmdOpenTestReport_Click()

Call verify_serialnumber 'ensure z has correct filename everytime command button is activated

Call fHandleFile("\\s02\s02usr\Traffic Signal Monitor Reports\" & z, WIN_MAX)

Dim sTopic As String
Dim sFile As String
Dim sParams As String
Dim sDirectory As String

'set default setting to be used
'if not specifically required
sTopic = "Open"
sFile = vbNullString
sParams = vbNullString
sDirectory = vbNullString

'type in full path of the file
sFile = "\\s02\s02usr\Traffic Signal Monitor Reports\" & z

Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWDEFAULT)

End Sub

It uses the windows file assocation method for opeining the file.

I have omitted much of the code that is irrelevent, so there are some variables, subs, and functions being used within the pasted code you see, but they are not needed for opening the file. The variable z gets it's value from another sub (verify_serialnumber)

If you are curious, I can show you all of it. My code writing is kinda sloppy sometimes....
 
What happen if you replace this:
Call RunShellExecute(sTopic, sFile, sParams, sDirectory, SW_SHOWDEFAULT)
with this ?
CreateObject("WScript.Shell").Run Chr(34) & sFile & Chr(34), , True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It does the same exact thing. It opens the file.

Is there a benefit of doing it your way?

 
Is there a benefit of doing it your way?
You don't need any API call ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top