Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

User input from Textbox or CommonDialog

Posted on 2000-02-26
3
Medium Priority
?
165 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

618 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