Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving without using the common dialog box

Status
Not open for further replies.

natashaXXX

Programmer
Sep 13, 2002
13
GB
I am creating a text editor using mdi form with menu, and child forms.

For SaveAs I am using the commondialog.showsave. I also want a save option which will recognise the active form. The file name is in the child forms caption, eg L:\test.txt, and I want to save immediately without going to the dialog box.

How can this be done? I've tried just moving the caption into commondialog.filename but without actually using the commondialog.showsave in the code for Save it won't work.

Many thanks

 
how about skipping the common dialog altogether?
the CD just gives you a name and you already seem to have that from the caption...
 
Do you have to ensure that the path exists as well or just save the file to its existing path? If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]

[cheers]
 
This is the code I'm using for save

strString = MDIForm1.ActiveForm.Caption
If strString <> &quot;&quot; Then

Close #f

f = FreeFile

Open strString For Output As #f

Print #f, MDIForm1.ActiveForm.txtNote.Text

Close #f

The code fails at &quot;open strstring ...&quot;
The file path is known, and is the same for all files being saved using this editor.

Problem occurs when:
open file 1 and amend
open file 2 and amend
change focus by making file 1 the active form and then save.
cheers
 
Here's what I've found:

Replacing your form reference with a constant string that includes the path (&quot;C:\DELETEME.TXT&quot;), and declaring the variables, your code works just fine for me.


Probably Extraneous And Unrelated: I'm not sure what events are calling your code, or exactly how and where your file reference variable f is declared (static? scope?). Which is to say, I realise that I don't have a complete context here. So: I'm not sure why you close #f before you reassign a new number to f and open a new file, since you always close the file opened for saving immediately after saving. Why you do so may not matter or be relevant, and no harm is done by closing a number that hasn't been opened, but I admit my curiosity :) .

Definitely Relevant To Your Problem:
You mention *where* the code gives an error, but not *which* error (number and description, please) is given.

Is it a 'Device Unavailable' error (Error #68 in Access 97 VBA), or something similar? Is it a 'Path/File access error' error (Error #75 in Access 97 VBA), or something similar?

You indicate that the form captions include the path. Is the path valid? Check the value of strString right before saving, and make sure the path exists -- either manually in testing, if the path is fixed; or in code &quot;on the fly&quot; by using the Dir command on the path portion of strString, if the path is not fixed.

For instance, if I use the string &quot;W:\DELETEME.TXT&quot;, I get the 'Device Unavailable' error (Error #68 in Access 97 VBA), because there is no drive W: on my system. Network drive mappings can often be the culprit in these kinds of cases, if you expect the drive to exist, but it doesn't.

For another instance, if I use the string &quot;H:\Administrator\DELETEME.TXT&quot;, I get the 'Path/File access error' error (Error #75 in Access 97 VBA), because although the path exists H:\Administrator on my system, I do not have read/write priveleges to the directory H:\Administrator.


If your error is not one of those I mentioned, post your error here (in this thread, not another), and we'll get back to you.

Good Luck, NatashaXXX, and future readers, -- C Vigil =)
(Before becoming a member, I also signed on several posts as
&quot;JustPassingThru&quot; and &quot;QuickieBoy&quot; -- as in &quot;Giving Quick Answers&quot;)
 
Many thanks for your reply. My mistake was when opening a file using FileOpen menu option, code similar to the following:

open statement
print statement
close statement

and then lock statement. This caused problems when I went to close #f in the save statement.

My reasoning was trying to leave a file in a state so that if it is open in the editor, no other application could access this. So I thought it would need to be left locked until the form was closed. On looking at this today it seems as though the unlock/lock statement only works between the open and close statements, so I'm not sure what to do.
Again, thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top