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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick code question

Status
Not open for further replies.

altaratz

ISP
Apr 15, 2001
73
US
I'm not a VB guy, so I was wondering if someone out there could give me a quick hit of code . . .

I need to check a directory for a text file for a data query - and if the text file does exist, then to query it (I've got this working) - I just need an if . . . then statement to skip to the sub routine if the text file doesn't exist (so I don't get one of those ugly run time errors) . . . so like

IF text file exist
Do this
Else if text file does not exist
Do nothing

Thanks for any help!

Ethan Altaratz
 
You should be able to simply use the syntax:
Else
Exit Sub

to exit the routine.

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
You only to test for the existance of the file. If it exists, whatever code follows the IF statement will be executed. If the file doesn't exist then nothing will happen anyway.

IF file exists
do this
do that
do the other

There's always a better way. The fun is trying to find it!
 
Right - but what would the syntax be for the If statement - like

If name.txt exists Then
Do This
Else
Exit Sub

Thanks again
 
Hi altaratz,

I THINK what you're asking for is a simple error trap. If so ..

Code:
[COLOR=darkblue]On Error Resume Next
[green]' Do your query of the txt file here - not sure exactly what it is[/green]
If Err.Number = 0 Then
    [green]' All is OK[/green]
Else
    [green]' Error - (probably) txt file does not exist[/green]
End If[/color]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top