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

Saving information 1

Status
Not open for further replies.

missmarci

Programmer
Jun 25, 2002
16
US
I have my form saved as an exe and it's ready for user input...however, once the user inputs information, i'd like to be able to have them choose save from the file menu and save the information and form (say, in my documents). I have the menu and get the save dialog box, etc., but i can't seem to get the code to make it actually save. Either it's way too simple and i'm making it hard, or it's way over my beginners' head. Please help. Thank you all
 
What kind of data do you have? What information does the user enter? Do you want to save the user input from a textbox to a text file? If you can provide a few more details I can get you started. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
It's a quote sheet where the user enters sizes and dollar amounts in text boxes, selects different types of labor and padding from option buttons and any extras from check boxes..then the totals are calculated and displayed in text boxes. I want to be able to say this is Mrs. Jones quote and save it to c drive or zip drive to recall when Mrs. Jones comes in and wants to purchase. thank you for your time
 
Do you just want to save it as a text file? It sounds like you should be uses a database of some sort. Do you have some kind of database? If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
i have a database in access that i set up for purchases containing customer information and info on their purchases and payments, but because i use this just for printing and giving to the customer, i wanted to be able to save it to recall and at the time i made it, i didn't even think to set up a database because we were just filing hard copies of the quote. i would like to set up a separate database to store this information in, but now the program is written, i'm not sure how to go about that...use VisData to create table with customer info? i'm getting more confused by the minute.
 
I am just as confused [bugeyed]! Does your current app interact with the database at all? You have a couple of options. You could set up your form to save each persons data to a text file under the persons name. You could set up the data base to store the data an then retrieve the data from the database and then use Crystal Reports to print your report for that customer. I am not trying to create confusion even though it looks that way. From your original post you stated that you have the menu and get the save dialog box, etc., but i can't seem to get the code to make it actually save., my question is how do you want to save it? As its own report, a screenshot of the form, a text file, a spreadsheet, a document, a table in a database? [neutral] If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
I think for right now, I want to just save each persons data to a text file under the persons name. that's what i was originally trying to do. i guess i confused myself by just now thinking of db options when you brought it up. if you could help direct me on saving data to a text file under their name, i would tremendously appreciate it (and I'll work on the db issues slowly on my own...of course, later down the road you may see a post or two for help on that, too! :) ). I appreciate your patience.
 
Ok, I will get you some code. [bigsmile] If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Just to make sure I am on the right page. Start a new project and add a reference to Microsoft Scripting Runtime from the Project menu. Then on the form add a textbox and change its name to txtName. Then add another textbox, a checkbox, 2 option buttons and a command button (leave them the default name). Then drop in this code

Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim s As TextStream
Dim sPath As String

sPath = App.Path & "\" & txtName.Text & ".txt"
Set s = fso.CreateTextFile(sPath)
s.WriteLine "Text1 = " & Text1.Text
s.WriteLine "Check1 = " & Check1.Value
s.WriteLine "Option1 = " & Option1.Value
s.WriteLine "Option1 = " & Option2.Value

Set s = Nothing
Set fso = Nothing
End Sub

Save the project and then run it. Place some new text in the txtName text box and then click the command button and then shut down the app. In Windows explorer look under the projects path and there will be a txt file with the name that you places in the txtText textbox. You can open the file and see the info from the other textbox, the checkbox and the two option buttons. Is this on the lines of what you are looking to do? If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
I did and when i clicked the command button I got this error message:
Compile Error
user-defined type not defined

and it shows fso As New FileSystemObject as highlighted.
 
You need to add the reference to the Microsoft Scripting Runtime from the Project menu. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
ok...got it. That will work,but what i actually wanted was to be able to call it back up looking just like the exe, only with their particular information dropped in. but what you gave me will definately work.
 
We can read in the text file and load the controls. I just wanted to make sure I was going in the right direction. Give me a little while and I will get you some more code. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
OK, this is not exactly the most elegant code in the world but I am just trying to get you started.

Private Sub Command1_Click() 'Save Button
Dim fso As New FileSystemObject
Dim s As TextStream
Dim sPath As String

sPath = App.Path & "\" & txtName.Text & ".txt"
Set s = fso.CreateTextFile(sPath)
s.WriteLine Text1.Text
s.WriteLine Check1.Value
s.WriteLine Option1.Value
s.WriteLine Option2.Value

Set s = Nothing
Set fso = Nothing
End Sub

Private Sub Command2_Click() 'Load Button
Dim fso As New FileSystemObject
Dim s As TextStream
Dim sPath As String

sPath = App.Path & "\" & txtName.Text & ".txt"
Set s = fso_OpenTextFile(sPath)
Text1.Text = s.ReadLine
Check1.Value = s.ReadLine
Option1.Value = s.ReadLine
Option2.Value = s.ReadLine

Set s = Nothing
Set fso = Nothing
End Sub

You may want to add some more fields etc etc so you can see exactly what it is doing. Make sure you remember the names of the files you would like to use (I saved with names) as there is no error checking. You may want to use a common dialog box to get the path of the file. I just did not have enough time. Hopefully this will get you started. If you have more questions let me know. Good Luck. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Ok, I will give this a shot. I really appreciate your time. I will let you know how it comes out.
 
Well I'm guessing it's time to call it quits for the holiday weekend because this isn't working. I get a type mismatch error and under command2_click this is highlighted:
Check1.Value = s.ReadLine. If you find time, I'd appreciate it if you could take another look. thank you
 
Make sure you change all the code as I changed these lines

Private Sub Command1_Click() 'Save Button
Dim fso As New FileSystemObject
Dim s As TextStream
Dim sPath As String

sPath = App.Path & "\" & txtName.Text & ".txt"
Set s = fso.CreateTextFile(sPath)
s.WriteLine Text1.Text
s.WriteLine Check1.Value
s.WriteLine Option1.Value
s.WriteLine Option2.Value


Set s = Nothing
Set fso = Nothing
End Sub


Also make sure you delete the old txt files because the data is different from the first post. Let me know. If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
foada:
ok, i got rid of the error (my brain is ready for the holiday already) but it still displays only the text, not the form (controls)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top