Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Open File Error With Common Dialog


Hi,

I have an open file button, which uses the common dialog control...

The problem is, is that the program errors if the cancel button is selected.

Please help me eliminate this annoying error?


Here is the code;

Private Sub cmdopen_Click()
Dim customer As onecustomer
CommonDialog1.ShowOpen
txtfilename.Text = CommonDialog1.filename
filename = txtfilename.Text
Open filename For Random As #1 Len = Len(customer)
numberofrecords = LOF(1) / Len(customer)
num.Caption = numberofrecords
Close #1
End Sub


thankyou,
Mark




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Common Dialog - Open File
Is there a way where you can load .rtf .doc into a textbox? not a richtextbox?

Edit by Moderator: In the future, please start your own threads, don't dig up 2 year old threads. Thanks.

Common Dialog - Open File
Hi guys,

would somebody PLEASE tell me why this code will not open a file. I read MikeJ's tutorial and I couldn't get it to work because I don't have a Rich textbox. Why do I need one? I'm trying to open any form from a File/Open menu. When I select the file, it goes into the window on the open dialog box but it just will not open. I've been step by step through two books and this forum for 3 hours with no luck. PLEASE HELP.

Thanks.


[vb]


Private Sub FileOpen_Click()

CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" 'This sets the filter for common dialog

CommonDialog1.ShowOpen 'Make common dialog show the open dialog

Open CommonDialog1.FileName For Input As #1


End Sub

[VB]

Open File Without Common Dialog
How can I have a open file dialog without using the common dialog within VB6? I do not want to create a new form and open it, I want a real open file dialog.

How can I do this?

Extending Common Dialog File Open
In XP when applying the cdlOFNExplorer flag I get the XP style File Open Explorer. Does anyone know of a way to send this dialog a message, or is there a Windows API that will allow me to extend the list of folders that appear on the left (currently it shows the standard My Computer, My Documents, etc). I would like to add a couple of my own - and even eliminate some of the existing ones that don't fit my application metaphor...
Ideas?
VB6 preferably - but .net is fine.

Open A Text File With Common Dialog
how do you open a text file with the common dialog control? and how do you display it on a text box? im a newb to the common dialog control.

Open File Common Dialog Question
Hi all.

I'm writing a basic wordprocessor, and I'm using a common dialog box to Open a file.

Is there any way to save the name of the folder in which the selected file is located?

So the next time the app is run, and the user opens a file, that the common dialog puts the user in the folder which he used last time?

Thanks,

Elizabeth

Help!!Open/save File With Common Dialog
Hi here,
I want to use a common dialog to open and save file. But as you know : the Open and Save As dialog boxes don't actually perform any function; they simply get the information from users. It's up to our application code to perform the necessary commands to complete the task .

And now I do not know how to do that.

Thanks in advance.
Shishydo

Open Text File In Common Dialog Control
On selecting a file (text) in a common dialog control and selecting "Open" the file does not open as expected - the dialog control window closes. What am I missing?

Open Database File With Common Dialog Control
I have a program that opens an Access Database file like this:


Code:
constr = "Provider=microsoft.jet.OLEDB.4.0;" & "Data Source=C:Whitelist.mdb"


I want to open it with the common dialog control so that I can distribute this app out to other people (because they may not store their database on the Root Directory of C:

I know how to open a file with the common dialog control but how to i tell this string to pull from the file i open?

Using Common Dialog...how To Show Only One Type Of File In Open/save Screen
how do i show only one type of file in a open/save common dialog screen.?

eg text editor only shows *.txt

How To Open/save A File At The Open/save Common Dialog Box?
Hi here,

I use the fileopen and filesave common dialog boxes.But I do not know how to really open or save a file in the open/save common dialog box.

Thanks at advance.

Shishydo

Common Dialog Open Dialog Box, With A Picture Preview?
Hey ya, is there any way i can add the picture preview in the attached image to my Common dialog control's open ?

I guess its a flag? but cant see it etc?

Open File Dialog Box Error Handling
Hello All,

I am working on a program for school and I am hoping someone could help me out with a small little thing.

When my form load a message box pops up asking the user to choose a file. The user clicks on OK and then the open file dialog box appears. Then user then clicks on the text file they want to open and it will open. If the use does not select a file and hits OK or CANCEL my program BOMBS.

Now my question: Can someone please help me out with the error handling technique for those two situations?

Thanks for your assistance.

Stacey

Common Dialog Open
I'm having a little trouble with how to go about this...

I have a Common Dialog to open .mp3 files...

The thing I need to know is, how do you make a Common Dialog Box (Open) select more than ONE file at a time to open?

Not only that, I need it to take the file name of just 1 file first, let me manipulate it with other things, then let me take the second file name and so on...

This is for ID3 v1 and v2 purposes and also for my playlist.

One easier quick question, inside a listbox, I want to drag an item into a different index then be able to drop it, and when that item is dropped, it takes the file index that it USED to be in, and use that to move an item in ANOTHER listbox from that OLD index to the NEW index. So... basically...

Start off with this:
List1 ------- List 2
Item 1 ---- Item1
Item 2 ---- Item2

To when I drag item 1 below item 2...
List1 ------- List 2
Item 2 ---- Item 1
Item 1 ---- Item 2

It does this...
List1 ------- List 2
Item 2 ---- Item 2
Item 1 ---- Item 1

Sorry this is so many questions! I know it should be split into more than one thread!

Open Common Dialog
Ad1, thanks for helping me before. It was just what I needed! Just one more thing:
I have a similar problem, but different.

How do I use the Common Dialog open box to open a text file to a text box?

Thanks

Open Common Dialog
can u clear a variable?

Dim stuff As Integer
stuff = MsgBox ("hey")
**** stuff


i want to make it so the variable doesnt even exist any more, can i?

whats happening is im using the dialog for open and then i cant open a second file because the variable is used already (i think)

thanks,
jared

Common Dialog Open?
i need to have an open directory dialog box, i think i need to use the common dialog control, but the book i have blows. I need one of the many experts here on vbforum to hold my hand, heres what i need , an open dialog box, that only shows directories, and when the hit ok, it adds the directory path to a string variable.
Thanks guys
Nick

Common Dialog Open
I need to find a way to find the open dialog window
i try so far findwindow("#32770","Open"). Of course it's work, however if the client user a french windows version i have to findwindow("#32770","Ouvrir").... and so on. Oh i can't only use the classname to find the windows. since there are many "#32770" classename open on my window. thanks for your help

Open .txt Using Common Dialog
using a common dialog box I want to open a .txt file and put the entire contents into a text box. (txtBody.text)

I know this is basic but in fact soo basic that I cant find any help on it. Sorry.

Many thanks in advance.

Common Dialog Open
Hello:

I am trying to get my common dialog box to go to a path that I give it before it opens. What happens is that it seems to remember the last directory it was in. How do you reset the directory without having to restart the exe.

Thanks.

P.S. commondialog1.InitDir does not seem to reset it

Common Dialog Open
Hi, I'm using the commondialog control to use the open dialog.
from this I want to select multiple files, this works fine

what I want to know is what is the maximum number of files
that i can select in one go

I know it has something to do with the maxfilesize

but i don't know what value to type in

any advice

thanks in advance

MICK

Open/Common Dialog Box/API...
Hi everyone...

I heard that the API calls for using the Common Dialog Box are
more efficient than using the equivilant OCX, but "damm" there
is a lot of code to digest...

I have searched a lot for my question, but each find was missing
a little something...

What I'm trying to do is to show the "Open" common dialog box.
The appropriate one for the OS. Then give it multiselect capability,
have the "Open as Read Only" selected by default, give it support
for long file names, have it open centered on my form, and upon
closing the box, get the multiple values from the filename string
(with removing the delimiters)...

I found the following code at the link below
http://vbnet.mvps.org/code/hooks/fileopensavedlghook.htm

The code at the above link does it all, except the bit about the OS
is written as a separate implementation. Without the OS code, the
dialog box that opens is custom (I think...), not OS aware... Basically my problem
is implementing the OS code into the rest of the code. When I did, it gave
me errors such as variable not defined... But it's not as simple as just declaring
the undefined variable...

I found it much easier to the all the above using the OCX equivilant, including
centering the box on my form when it opens... My problem with this method is that
I don't know how to get the multiple selected filenames, and remove the delimiters,
upon closing the box...

I'd rather use the API if someone can show me how to implement the OS code correctly...
Or as a last resource, using the ocx, on how to get the multiple values and remove the delimiters...

Any help is appreciated...

D-Race



Edited by - D-Race on 11/16/2004 2:59:21 AM

Open Common Dialog
Is there a way to disable the open button on a common dialog (like in the office products) until a file is put in the filename field?

Help With VB Common Dialog For Save/Open
I down loaded a VB common dialog from one the threads that someone posted. I am trying to use it but I have some trouble Opening a file and Saving a file.

Open a file:
FileDialog.sFilter = "Service files [*.dat]|*.dat"
MyfileName = ShowOpen.nFilesSelected

This code generates no error but does not capture the filename. It captures the opened file name, the opened file name is 1. The same is true for Saving a file.
Save a file:
FileDialog.sFilter = "Service files [*.dat]|*.dat"
NewfileName = ShowSave.nFilesSelected
This save code does save the newfile as number 1, which I think it should not be a number.

Please one help me in opening and saving a file.

Thank you.

MydanVue

Common Dialog Controls - Open
i'm trying to learn how to use common dialog control. i've searched through other threads but still need some help.

the program i'm writing has an open command button that when clicked opens the open dialog box. another button labeled enter is supposed to take the data in the text boxes and put it in the file. the file must be opened in append mode. can somebody help me understand how to do this? i understand how to use the regular open "filename" for append as #fn1 but i'm unsure how to implement the open dialog box....i don't have msdn installed (using a version from a book that didn't include it) so i can't go to msdn for reference.

this is the code i have so far for the box, i copied it out of the appendix in the book i'm using but it doesn't cover everything in detail so i'm unsure of what some of these things do.


Code:
dlgOpen.FileName = ""
dlgOpen.Flags = cdlOFNFileMustExist _
Or cdlOFNNoChangeDir Or cdlOFNHideReadOnly
dlgOpen.Filter = _
"CSV Files (*.csv)| *.csv|All Files(*.*)|*.*"
dlgOpen.FilterIndex = 1
dlgOpen.CancelError = True

On Error Resume Next
dlgOpen.ShowOpen

If Err.Number <> 0 Then
Exit Sub
End If

does anybody have a link to a forum or page that explains the common controls in detail? and maybe has a list of available flags i could use?

Common Dialog Open Folder
Hi people i need to use a common dialog control to open a folder, is it possible? The user should select a folder, not a file
i am not sure how to do this! is there any flags to perform this?
thanks in advanced!

Using An ADO Datacontrol And A Common Dialog To Open A DB
I trying to open a database using the commondialog showopen to get the path. But I can't get the control to take the information and open the database. Please help...

here's my open code:

Private Sub mnuOpen_Click()
On Error GoTo Cancel_Error

Dim strConnection As String

With cdlDBOpen 'common dialog name
.Filter = "Access Batabase (*.mdb)|*.mdb"
.CancelError = True
.ShowOpen
strConnection = .FileName
End With
With adoSubjects ' datacontrol name
.ConnectionString = "Microsoft.Jet.OLEDB.3.51" & "Persist Security Info=False;" & "Data Source=" & strConnection
.CommandType = adCmdTable
.Mode = adModeShareDenyNone
.CursorLocation = adUseClient
.RecordSource = "[Subject Query]"

End With


Cancel_Error:
Exit Sub

End Sub

Can Common Dialog Open Whole Folder?
Hello all,

I was wondering, if I could get the common dialog control to open all the contents of a folder, just when the folder is selected? When I double click the folder it only shows it's contents, can this not be done?

Open Common Dialog Control
this is my code


Code:
Private Sub mnuOpen_Click()
CommonDialog1.Filter = "All Compatible Picture Types (*.Jpg *.gif *.png)|*.jpg"
CommonDialog1.ShowOpen

Dim intpicture As Long
intpicture = FreeFile

Open CommonDialog1.FileName For Output As #intpicture
Print #intpicture, Image1.Picture

Close FreeFile
End Sub

the problem with this is i get a permission error, the error is...

Run Time Error '75'...
Path/File Access error

any help is appreciated, thanx

Common Dialog Open Folder?
I've searched and searched for a solution to this problem, but before I give up on this entirely, I thought I'd ask here...

Is there a way to use the Common Dialog control to select a folder rather than a file? Specifically, I would like the user to click a browse button and--through the Common Dialog interface--be able to select an empty directory.

I know there are other ways to do this, but I need, specifically, the ability to create a new folder if one does not exist. The Common Dialog interface allows this. Additionally, I use the Common Dialog control elsewhere on this form to open a file, and I would like to keep the interface consistent.

If anyone could point me in the right direction, I sure would appreciate it.

Many thanks,
Steve

Open Ftp From Common Dialog Control
Hello,

I would like to create an interface which allow the user to select
files from a ftp site using the common dialog contro. And after some
manipulation in the program, the new output file will go to the same
ftp site.

My problem is firstly, when I select a file from the ftp site, its
..FileName of the common dialog control falls into the Temporary
Internet Files folders, but what I need is I do need to know the exact
ftp site that the user pick.

Besides, same thing for the output directory, I need to know the ftp
site so that I can upload my converted file back to the ftp site.

Please help.

Thanks in advance. Any help will greatly appreciate.

Wanda

Re: Open/Common Dialog Box/API &gt;&gt; Revisited...
Hi everyone...

minor28, if you are reading this post, I have a couple of questions regarding the 2 lines
in your code, that I have marked in red...

This code was under the form...

Code:Dim StructLen As Long
    Dim Files() As String
    Dim i As Integer
    
    Text1 = vbNullString
    List1.Clear
    
    OSVI.dwOSVersionInfoSize = Len(OSVI)
    GetVersionEx OSVI
    If OSVI.dwMajorVersion = 5 And (OSVI.dwMinorVersion = 1 Or OSVI.dwMinorVersion = 0) Then
        StructLen = Len(pOfn) 'Win2k or XP
    Else
        StructLen = Len(pOfn) - 12
    End If
    
    pOfn.lStructSize = StructLen
    pOfn.flags = OFN_ENABLEHOOK + OFN_ALLOWMULTISELECT + OFN_EXPLORER + OFN_LONGNAMES + _
    OFN_FILEMUSTEXIST + OFN_SHOWHELP
    'If you have a custom template
    'pOfn.flags = pOfn.flags Or OFN_ENABLETEMPLATE
    pOfn.lpfnHook = GetProcAddress(AddressOf OFNHookProc)
    pOfn.lpstrFilter = "Images (*.bmp;*.jpg;*.jpeg)" & vbNullChar & "*.bmp;*.jpg;*.jpeg" & vbNullChar & vbNullChar
    pOfn.nMaxFile = 1024
    pOfn.lpstrFile = vbNullChar & Space$(1024) 'Reserve space in buffer
    pOfn.lpstrTitle = "Select Files"
    pOfn.dwReserved = 0&
    pOfn.pvReserved = 0&
    pOfn.hwndOwner = Me.hwnd
    
    GetOpenFileName pOfn
    Files = Split(pOfn.lpstrFile, vbNullChar)
    'First file is the path to all files
     
    If UBound(Files) = 2 Then
       Form1.List1.AddItem Files(i)
    Else
       For i = 1 To UBound(Files) - 1
           If Not Files(i) = vbNullString Then
              Form1.List1.AddItem Files(0) & "" & Files(i)
           End If
       Next i
    End If
    Text1 = Replace(pOfn.lpstrFile, vbNullChar, "; ")

First of all I ran some tests to determine what values I should use in these lines.
I ran these tests because I have very little knowledge about API's.

My first question is what do the "vbNullChar" do in the code?
My second question is from the tests I ran... I had a folder with 70 picture
files in it, and as the code stands above, I ran the program, and when I selected all
the files and hit open, nothing happened, not even an "overflow" error...Then I changed
the values in the two Red lines, to 32000, and it worked. Then I changed only the first
Red line value to 32000, and it still worked. But changing only the second Red line value
didn't work...So do I need to change both Red line values to 32000, or will changing only
the first Red line value be correct coding?

I'd appreciate it, if anyone else can answer this questions also...

D-Race



Edited by - D-Race on 1/6/2005 8:43:31 AM

Use Common Dialog To Open A Database
I'm hoping someone can help me with a newbie problem here...

I want to use a common dialog to allow a user to open a database. How do I get the database name and path from the common dialog and then open the database for use by some simple forms.

Thanks in advance.

Open Folder With Common Dialog
Can someone tell me how to open a folder and get all of its contents using the commondialog control? Thanks

Open Folder Location Common Dialog
Hi guys, ive search the forum for answer to this but i cant find a consise answer to my question, which is -

when using the common dialog control, how do i get it to return a drive/directory location. not the file.

Im using it to open a project location, in which im savin all the files.

Cheers
Jim

Open Common Dialog In Details View
When you start an open common dialog box, there is a box in the upper right hand corner that lets you choose the view.

In code, how do you make the dialog box show a chosen view (say the 'details' view) automatically when it opens?

Common Dialog Problems (show Open)
PLEASE I am desparate for help. I have been trying to find a solution for days but have been unsuccessful.

Anyway, here's my problem. I am running Visual Basic 6 complete with SP5. I have written an application and have this app working perfectly on my system. I have also packaged this app using the VB Package and Deployment Wizard and have verified that the installation package works properly.

Now, here's my dillema. This application seems to work perfectly on any system that has Visual Basic 6 installed (I have currently tested this app on five different systems, all running Visual Basic 6, and the app runs perfectly). However, whenever I migrate this application to any other system that does not have Visual Basic installed the call to show the FILE->OPEN dialog box fails. There aren't any errors displayed. It simply does nothing when this method is invoked. Also, this problem does not seem to be Operating System specific as I have encountered these same problem on machines running Windows 98, Windows 98SE, Windows 2000 Workstation, Windows NT 4.0, Windows ME, and Windows XP.

I have since visited the Microsoft MSDN site and downloaded the VB6 runtime files and installed them on the target system but this did not resolve my problem.

I have also taken two approaches to solving this problem. Originally I used the CommonDialog controls to invoke the ShowOpen method. However, upon encountering these problems I modified this section of the code to instead invoke the Open dialog box using Win32 API calls. Unfortunately this didn't work either.

I'm totally out of ideas and desparately need help. If anyone has any ideas it would be greatly appreciated. Thanks.

Norm.

How Can I Open Common Dialog For Directory Selection Only?
hi all..
How can I open Common dialog for Directory Selection only?

Common Dialog Save/Open And Vista
Hi, a fairly simple question (i think). I've tried using the Save/Open Common Dialog box within an application i'm making and i'm having problems using the extension filter. I think this is vista thing, having said that i havn't tried it on XP so it might just be me.

Open Common Dialog In Details View
When you start an open common dialog box, there is a box in the upper right hand corner that lets you choose the view.

In code, how do you make the dialog box show a chosen view (say the 'details' view) automatically when it opens?

Multi Select In Common Dialog Open
Is there a way to set a common dialog to allow the user to select more than one file at a time in the Open Dialog?

I ws thinking there would be a flag to set, but I looked around and couldn't find one so I am asking oyu guys.
Thanks

Common Dialog - Long Filenames In Open
Greetings, all! New poster here.

I'm using the Common Dialog control to select both a file to be processed and the name of the new file I intend to create. For the former I use ShowOpen, for the latter I use ShowSave.

Before showing either dialog, I set appropriate flags including the cdlOFNLongNames which, I understand, is supposed to allow for long filenames.

When the user selects the file he/she wants to process I use the ShowOpen method but am getting DOS-formatted listings (i.e. COPYOF~1.TXT) of the existing files. However, when I use the ShowSave method I get a different dialog that shows long filenames correctly.

Any idea what the deal is here?

I'm using VB5 Pro.

Thanks in advance!

COMMON DIALOG - Save, Open, Filetypes, Etc...
I was wondering if anyone could help me with a few things here. I have written the code for the open command, but when the common dialog box comes up, the default "Files of type" is set to nothing. How, by code, do I put things in there, such as "*.txt, *.doc, All Files"?
My open command looks like this:

Private Sub mnuOpen_Click()
'opens selected file
Dim Filename As String
CommonDialog1.ShowOpen
Filename = CommonDialog1.Filename
If Filename <> "" Then
Open Filename For Input As #1
rtxticd = Input$(LOF(1), #1)
Close #1
End If
End Sub

How would I write code similar to that but for a save method? I read all these other peoples posts for open and save, and they all use list boxes, but I find that they are not neccessary. How would I write the save code to be similar to the one above?

In my program, there are options to change text color, size, and so forth. For the save command, how would I write code so that it would save all the properties of the text that the user hath input. If they changed the color of the text to red, and wanted to save, it would save that the text was red, not just what the text read.

Any help you can offer is of great appreciation.
Thank you all.

-UseTheMan

How To Open Common Dialog In Network Places
Is there a way to have the Common Dialog open looking at Network Neighborhood? I'm trying to look at a list of what machines are available on a small win 98 network, and could do that if I can open the Common Dialog Open command with a start directory of My Network PlacesEntire NetworkMicrosoft Windows Network but that doesn't work?

Any suggestions, or is there a better way in Win 98 to get a list of network machines? (Easily done in XP with an api call that's not available in 98)

Thanks,
Larry L

Restrict Open Common Dialog Accessibility
I need to restrict the visibility/accessibility of certain folders from common dialog control. How do I do that? Say for instance I need that the common dialog control's Open dialog show only the local disk drives and does not let the user browse the network. How do I achieve this?

New Drive Not Displaying In Open Common Dialog
Hi,
I am using Open Common Dialog in my VB code, which works fine normally, but if I plug in my Flash drive, and Click on the icon to open Common Dialog, I do not see flash drive in the drop down list.
If I cancel the window, and try again, it appears. I did wait long enough for the drive to register, and it can be seen in Explorer, but in this program it is always failing the first time.
Appreciate any feed back

Thanks

After Open Common Dialog Hotkeys Don't Work
have a form that opens the common dialog thru api
After i close the common dialog my form does not process hot keys like:

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If Shift = 2 Then
Select Case KeyCode
Case vbKeyA
cmdAddressBook_Click

The form has the focus and i can type into textboxs etc
How can i correct this?

Common Dialog - Open Folder Path
how do i add a folder path into a string or use the path with common dialog box?


VB Code:
Private Sub mnuBrowseFolder_Click()On Error GoTo errBrowseFolderWith DlgBox    .FileName = ""    .DialogTitle = "BrowseFolder"    .CancelError = True    .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer    .Filter = "-- Favorite Folder Path --|"    .ShowOpenEnd With 'MsgBox DlgBox.FileName errBrowseFolder:Exit SubIf Err.Number = 32755 ThenEnd If End Sub

Open Word Document With Common Dialog Box
In a VB program, I am showing the common dialog box to retrieve a word document. Then the user clicks on which word document to open. The document opens but it opens minimized on the task bar. Does anyone know how to have the word document maximized when it opens.
My code is:
Dim strfilename As String
Dim word_app As New Word.Application
Set word_app = CreateObject("Word.Application")

strfilename = ""
With CD
.CancelError = True
.Filter = "Microsoft Word (*.doc)|*.doc"
.Flags = cdlOFNHideReadOnly _
Or cdlOFNFileMustExist Or cdlOFNExplorer
.InitDir = C:Word
.ShowOpen
strfilename = .filename
End With
word_app.Documents.Open (Trim(strfilename))
word_app.Visible = True
Set word_app = Nothing

Copyright © 2005-08 www.BigResource.com, All rights reserved