Solved

User input from Textbox or CommonDialog

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now