So I wish to save the contents of a VB form i.e. text box entries and combo box selections when the form has been used.
Then on reload of the word document I would like this saved data to be retrieved so that the entries can be edited.
I have code for doing this.
I use this code to retrieve from the file.
Dim sLine As String Open dlgCommon.FileName For Input As #1 Line Input #1, sLine
txtedit.Text = sLine
' Etc...
Line Input #1, sLine
txtedit2.Text = sLine
Line Input #1, sLine
txtedit3.Text = sLine
close #1
my question is if I have multiple forms can I save their data to one file or do I need to use seperate files for each form.
Product name
Recipe Number
Product Type
Project Number
Project manager
factory
Date of last update
Username of Updater
2 command buttons
View
Edit
view shows the document
edit loads a second form
identical to the first but with text boxes instead of labels
allowing you to edit the info date and username are updated automaticaly so remain as labels.
2 command buttons confirm and cancel
confirm loads a third form
cancel exits the code.
the third form contains many tabs to do with information to be inputted in to the document answering questions prompts for data to be inputted into the document. answers are from drop down boxes. text is entered into text boxes.
again 2 command buttons confirm and cancel.
confirm then automates a document to be generated about 7 pages of tables and charts ect all to a standard format.
what i want is to save the state of the forms on close so that when reloaded the user does not have to input all the info again if they wish to edit a small piece.
so what i have achieved so far is i know how to write and to read from an existing text file.
reading from file
Code:
Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
Open "" For Input As #iFileNo
Line Input #iFileNo, sFileText
summary_edit.Product_Name_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Recipe_Number_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Product_Type_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Project_Number_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Project_Manager_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Factory_Edit.Text = sFileText
Line Input #iFileNo, sFileText
summary_edit.Updated_Edit.Caption = sFileText
Line Input #iFileNo, sFileText
summary_edit.By_Edit.Caption = sFileText
Close #iFileNo
writting to file
Code:
Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
Open "" For Output As #iFileNo
Print #iFileNo, Product_Name_Edit.Text
Print #iFileNo, Recipe_Number_Edit.Text
Print #iFileNo, Product_Type_Edit.Text
Print #iFileNo, Project_Number_Edit.Text
Print #iFileNo, Project_Manager_Edit.Text
Print #iFileNo, Factory_Edit.Text
Print #iFileNo, Updated_Edit.Caption
Print #iFileNo, By_Edit.Caption
Close #iFileNo
I dont know how to create a text file probs pretty easy
problem 1
I need to know how to check if the text file exists and if not create one.
problem 2 more tricky than one
There will be a standard template document with no text file. When opened i can use the me.filename to determine if its the template and then prompt the user to saveas new name to do with the specific project. there must then be a specific data file for each project.
I want to be able to have say file project1 and then a text file "project1_data"
linking this back to problem one how do I check to see if this data file exists based on the name of the wordfile. me.filename +"_data" needs to be the name of the file
and lastly the files need to be transferable so folder containg word file and data file can be emailed and the code automatically adjusts for new file path.
What you are doing, in my eyes, is totally against principle of using vba/Access/Word.
Why?
You can use Access to do all this and save the data in tables, instead of flat txt files. Not only do you have the word document but you also need a supporting txt file.
Having seperate forms for viewing and editing is also wrong. You would simply chage the enabled/locked property on / off. How do you distribute this application, if you can call it an application, when everything is modular to that pc.
I think you need to look at moving your concept to Access straight away.
What gave you the idea of doing this in Word anyway?
Don't think I am trying to belittle you, I am not, its just I cannot find any valid reasons for doing it this way. Access can open word documents and populate them with data and produce tables, graphs etc.
Hope I have not offended you, its just a bit of constructive criticism.
No im not offended in the slightest critisism is always good.
One answer though we don't have access. Word and excel and outlook are the only common office programs we have across our sites world wide. Our database system is designed in house this is just a small scale project so we have no support from the people with the know how on our database system.
The two seperate forms for viewing and editing was for asthetics labels look better than text boxes. But text boxes indicate data entry more clearly than labels.
There are no charts but there is a flow diagram. So access would be fine for the tables but can you use it to draw flow charts?
In terms of sharing it if i can read the filepath of the of the open document i can set the filepath of the data document because it will be xxxx_data all the time.
Therefore moving the two files together should work.
I know it may not be pretty, logical or time effective but its the only option we have right now if the trial is succesful then we might get access to the main databases.
There are not many businessess out there that have Microsoft Office WITHOUT Ms Access. You would only need one machine to have it one to create the front end then you can distribute it in a runtime version. As an alternative, you say you have Excel. You could use Excel to store your text file data in and enumerate the rows to find the record you want. Just a suggestion.
I also work for a Worldwide business (US in origin) that will not 'officially' release Access with its MS Office applications. They don't recognise it as an approved program, and refuse to support it in any way. Therefore I had a very tough time getting Access installed throughout our Dept.
I wish I knew about the runtime version earlier!! I ended up getting 30 issues of Access 2003 for each user. I really like this solution!