Solved

User input from Textbox or CommonDialog

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specify ip address in my connection string for sas 2 65
Sending a email via excel using vba 6 96
Passing a Text Box name to a Sub 6 99
checkbox to hide entire section 10 40
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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