Solved

User input from Textbox or CommonDialog

Posted on 2000-02-26
3
162 Views
Last Modified: 2010-05-02
I have provided both Textbox and CommonDialog for the user to enter a filename. So far I just managed to get the user to click a button to call the CommonDialog control and when a file is selected, then the filename will appear in the Textbox. But if the user straight away write down the filename in the Textbox, then there will be an error.
How can I make the user to enter the filename either using the Textbox or the CommonDialog control?

Below is the coding:
Private Sub Button1_Click()

CommonDialog1.showOpen
txtFilename = CommonDialog1.Filename
InputFile = txtFilename

End Sub
0
Comment
Question by:suhani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:fibdev
ID: 2562008
Private Sub Button1_Click()
  Dim InputFile as String
  CommonDialog1.filter = "All Files (*.*)|*.*"
  CommonDialog1.showOpen
txtFilename.text = CommonDialog1.Filename
InputFile = txtFilename.text

End Sub
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2562011
Just in case, try this:

Private Sub Button1_Click()

  Dim InputFile as String
  CommonDialog1.filter = "All Files (*.*)|*.*"
  CommonDialog1.showOpen
    If CommonDialog1.filename <> null then
     txtFilename.text = CommonDialog1.Filename
    end if
InputFile = txtFilename.text

End Sub


0
 

Accepted Solution

by:
faintforyou earned 50 total points
ID: 2562420
I think that the error you have encountered is perhaps because
the text in the textbox that the user
had typed is not really a filename

Then you can use the method below to
ensure that the user have typed in
a correct filename.

Add a button on your form named
btnConfirm

Private sub btnConfirm_Click()
  On Error Goto Err_Handler
     FileLen(txtFilename.text)
     'if the file did not exist
     'there will be a error
     
  Exit Sub
Err_Handler:
   Msgbox "You have not input a valid _
           File Name.Please check it."

   txtFilename.Text="" 'or any you like

End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question