Solved

User input from Textbox or CommonDialog

Posted on 2000-02-26
3
163 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

724 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