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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CommonDialog ShowSave

Status
Not open for further replies.

rlusk49

Technical User
Nov 7, 2002
18
0
0
CA
Can anyone help me with the ShowSave method of the CommonDialog box. It's the first time I am using this control. When I open a particular form, I would like to save the form to my hard disk. I assume I can do this with ShowSave. First of all, am I right and secondly what code to I need besides.

Dim Filter As String

Filter = Filter + "File Types (*.doc)|*.doc|"
SaveDialog.Filter = Filter
Me.SaveDialog.ShowSave

Am I way off base or can this be done?
 
With Dialog
.CancelError = True
.Filter = "File Types (*.doc)|*.doc|All Types (*.*)|*.*|"
( .Flags = cdlOFNHelpButton Or cdlOFNExplorer)
.ShowSave
if err=0 then
strThisFile=.FileName
endif
end With

®od


®od
--------------------------------------some Music?
 
Thanks for the tip but you're going to have to bear with me. I understand most of it but what exactly is strThisFile? Does this contain the info I want to save? Do have to put the info into a variable first? I am guessing that I cannot save the whole form itself but only certain contents of the form.
 
I think that where you're confused is in what the CommonDialog.ShowSave does. It doesn't save anything, all it does is display the save dialog box, allowing the user to move to different drives, folders, etc. and pick a filename to save "something" to. Then your program will have to take the filename from the showsave dialog and write whatever you want to save to that file. The showsave won't actually do anything (won't even open or create the file).
 
I really did understand that but what can I save to the file? Can I save the whole form itself ( I am guessing no) and how do I actually save. If I have numerous text boxes on the form, how do I save the contents to a file?
 
I'm not sure what all you're trying to save, but you could save whatever you want, you just have to go through each piece and same them separately.

'Write form location, etc. to file
Dim c As Control
Open "d:\test.dat" For Output As #1
For Each c In Me.Controls
If TypeOf c Is TextBox Then
Write #1, c.Name & "=" & c.Text
End If
Next
Close #1

When you want to load it back in, you just read the file and then set the form info and each control. For instance, you read the line from the file as "controlname=value" (any format you want as long as you know the name of the control and what to put in it. For this example, assume you read the file, parsed the pieces and stored the name of the textbox in a variable called sCtrlName and the value in a variable called sValue. Then put the value into that control similar to below:

Dim sTemp As String
Dim sCtrlName As String
Dim sValue As String
Open "d:\test.dat" For Input As #1
While Not EOF(1)
Input #1, sTemp
sCtrlName = Left(sTemp, InStr(sTemp, "=") - 1)
sValue = Mid(sTemp, InStr(sTemp, "=") + 1)
CallByName Me, sCtrlName, VbLet, sValue
Wend
Close #1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top