-
Ok, this is my situation. I have a textbox(Which only reads #'s) and a command button on form1.
What i want to do is that when the command button is clicked it checks to see if the numbers written in the text box are files that exist in the current dir. If not then msgbox "Files do not exist in current dir" If they do then form2.visible = true
Note: the file names do not hold extensions, ex. 1234 is the file name not 1234.txt....thank you
-
Give this a whirl
Code:
Private Sub Command1_Click()
If Dir$(Text1.Text) <> "" Then
'the file exists
Form2.Visible = True
Else
MsgBox "File Does Not Exist In Current Directory"
End If
End Sub
-
Didn't work
With the code that was given, no matter what i typed in the text field i get a file not found box.
-
Rephrase that
Not a file not found box but the MSGBOX we request it to ask when a file is not in that directory. I know the code is similar to the one given, and i been cracking at so many different ways to run it. Someone help, if your still ou there lain hook it up!
-
The code Lain gave you works fine, check the files you're looking for actually exist in the current directory which you can get using the CurDir command, i.e.
Debug.Print CurDir
-
try this code, it will check to see if a file exists using error handling
************************************************
Private Sub Command1_Click()
Dim FilePath As String
On Error GoTo NoFile
FilePath = CurDir & "\" & Text1.Text
Open FilePath For Input As #1
Close #1
'put things to do with file that exists between here.
MsgBox "Good file"
'And Here
Exit Sub
NoFile:
MsgBox "No File"
End Sub
************************************************
put what you want to do with a good file in between the comments and a bad file is in the labe NoFile.
Hope this helps.
-
Damn
It searchs the file in which the *.mak file is right? And does it matter that I have VB 3? It's frustrating cause it seems so simple.
-
dmartin
I get resume errors with your code, ;o\ THanks for helping me guys dont give up on me now
-
I'm on to it
Leans code does work
If Dir$(Text1.Text) <> "" Then
'the file exists
Form2.Visible = True
Else
MsgBox "File Does Not Exist In Current Directory"
End If
however i have to put a \ in the text box for it to read files....how would i get it to put the \ automatically without having to actually type it in the text box? That would make it work!!!
-
If you only need the backslash used in the Dir function you can just concatenate it:
If Dir$("\" & Text1.Text) <> "" Then ... etc etc
-
that easy huh
Hehe thanks for all your help guys, i wound up figuring out the last part though, however made it much more complicated then what you wrote hehehe. I put
a = "\"
b = (text1.text)
If Dir$(a + b) <> "" Then
'the file exists
Form2.Visible = True
Else
MsgBox "File Does Not Exist In Current Directory"
End If
cool huh? I was proud as hell, I looked at a how to add two times together example and took the idea from that. It works!!! Thanks again for all your help guys!