473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Error handling

Ive written a pretty basic program for work that offers the user a number of
buttons to selct that then open an Excel Template.

The code is basically as shown below, the first section sets the base path
for the Templates and gives the user the option to cahnge should the network
position move. The second part is the code for loading the file on
activation of the corresponding button.

All very simple and functional.

What it doesnt od though is raise an error if the template does not exist.

I would be grateful if someone could give me a clue as to how to go about
this.

Private Sub Menu_Click()
Dim sNewPath As String

sNewPath = InputBox("Enter new location of template files:", ,
"\\agb-dds01\hdd3\Request-templates\")

If Len(Trim(sNewPath)) > 0 Then
m_sBasePath = sNewPath
MsgBox "Base Path changed."
End If
End Sub

Private Sub Command1_Click()

If Right$(m_sBasePath, 1) <> "\" Then
m_sBasePath = m_sBasePath & "\"
End If

ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
Unload Me

End Sub

Drink and drugs cause amnesia and other things I can't remember... Another
meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
Bastard Group

http://uk.geocities.com/da************@btinternet.com/
http://www.btinternet.com/~fratton/
Jul 17 '05 #1
5 4358

"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If
Jul 17 '05 #2
Using that code returned the following error message

Run time error 52 - bad file name or number, this relates to the line
starting If Dir(m_s....etc

I almost had a psychic girlfriend but she left me before we met. Another
meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
Bastard Group

http://uk.geocities.com/da************@btinternet.com/
http://www.btinternet.com/~fratton/

"Steve Gerrard" <my********@comcast.net> wrote in message
news:Qu********************@comcast.com...

"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If

Jul 17 '05 #3
Steve Gerrard wrote:
"Spudgun" <no*@here.com> wrote in message
news:ch**********@hercules.btinternet.com...
| Ive written a pretty basic program for work that offers the user a
number of
| buttons to selct that then open an Excel Template.
|
| The code is basically as shown below, the first section sets the base
path
| for the Templates and gives the user the option to cahnge should the
network
| position move. The second part is the code for loading the file on
| activation of the corresponding button.
|
| All very simple and functional.
|
| What it doesnt od though is raise an error if the template does not
exist.
|
| I would be grateful if someone could give me a clue as to how to go
about
| this.
|

If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
Else
ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
Me.hWnd
End If

G'day Steve,
Sorry to jump into someone else's thread.
2 quick questions.
1). Why the "Me.hWnd"?
2). How would I check if a folder existed?
tia
build
Jul 17 '05 #4

"build" <bu*****@datafast.net.au> wrote in message
news:41********@news.alphalink.com.au...
| Steve Gerrard wrote:
|
| > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
| > Msgbox "Can't find " & m_sBasePath & "Static Airbag
Template.xlt"
| > Else
| > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
"open",
| > Me.hWnd
| > End If
| >
| G'day Steve,
| Sorry to jump into someone else's thread.
| 2 quick questions.
| 1). Why the "Me.hWnd"?
| 2). How would I check if a folder existed?
| tia
| build

1. ShellEx is a Windows API call. If a Windows API call asks for a
window handle, you give it a window handle, and don't ask why. :)

2. Here is a simple function demonstrating use of Dir and GetAttr:

Private Sub Command1_Click()
CheckPath "C:\Program Files"
CheckPath "C:\Windows\notepad.exe"
CheckPath "Sheer Nonsense"
End Sub

Private Sub CheckPath(Path As String)
If Dir(Path, vbDirectory) = "" Then
MsgBox Path & " not found"
ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
MsgBox Path & " is a file"
Else
MsgBox Path & " is a folder"
End If
End Sub

Jul 17 '05 #5
Steve Gerrard wrote:
"build" <bu*****@datafast.net.au> wrote in message
news:41********@news.alphalink.com.au...
| Steve Gerrard wrote:
| > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
| > Msgbox "Can't find " & m_sBasePath & "Static Airbag
| > Template.xlt"
| > Else
| > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
| > "open",
| > Me.hWnd
| > End If
| >
| G'day Steve,
| Sorry to jump into someone else's thread.
| 2 quick questions.
| 1). Why the "Me.hWnd"?
| 2). How would I check if a folder existed?
| tia
| build

1. ShellEx is a Windows API call. If a Windows API call asks for a
window handle, you give it a window handle, and don't ask why. :)

2. Here is a simple function demonstrating use of Dir and GetAttr:

Private Sub Command1_Click()
CheckPath "C:\Program Files"
CheckPath "C:\Windows\notepad.exe"
CheckPath "Sheer Nonsense"
End Sub

Private Sub CheckPath(Path As String)
If Dir(Path, vbDirectory) = "" Then
MsgBox Path & " not found"
ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
MsgBox Path & " is a file"
Else
MsgBox Path & " is a folder"
End If
End Sub

Thx Steve, just what I was after, appreciate your taking the time :-)
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a...
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
9
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.