Two ways access is not exposed: SaveAsText and LoadFromText

Source: Internet
Author: User
Tags ole

A long-written article, suddenly can't find, write in their own blog to be retained.

Should be invited to the Yellow Sea, suddenly want to write something of their own things, all of a sudden as if do not know what to write, research access so many years, feel is in the enterprise application, and there is no advanced skills, also did not belong to their skills, had to brain, squeeze something out, hope to be worthy of the Yellow Sea and everyone:

There are two undisclosed methods for application objects in Access, one of which is SaveAsText, The other is loadfromtext. I remember just learning access soon, when studying FMS an analytical tool, trace found that it will always produce some temporary files, the temporary file analysis, and found it with the VB form file similar format, so it is estimated that Microsoft can convert the form of access to text format, and to mention For an inverse phase conversion method. So found a deep interest, and then found these two methods.
Although Microsoft has some other relatively useful unpublished properties, but I spend the most time on these two methods, because it does use value, so talk about their experience for many years.
These two methods are not necessarily supported in future versions of Access, so I'm not suggesting that you use them, but because some features can be used to achieve this, it saves a lot of time, so in some cases I will still use it, at least the existing version of Access supports this method. If the same functionality can be achieved by using access in a normal way, I recommend that you use Microsoft's public approach. Remember!


Use 1:

Use
Application.saveastext acform, "My form", "C:\test.txt"
Export the entire form to a text file, package it to a friend, and let friends use it again
Application.loadfromtext acform, "My form", "C:\test.txt"
And then lead back. You can compress the package transfer.

Use 2:
You can save a form to a text file and then store the text file in an OLE field so that the interface and code for the entire form can be saved to the Access table, which is useful for writing code base manager. In use, you can also instantly restore text files to a form, allowing users to instantly preview the effects of this technique

Use 3:
Save the form to a file file, using regular expressions to analyze the code, you can analyze the syntax, code structure, syntax errors, word count, etc., you can refer to the FMS of an Access analysis tool, it has some features, you spend a half year, to make it should be no big problem. Remember to let me try the source code OH:)

Use 4:
A real global replacement, generally we need to replace the name or content of a property in the form, and we need to change it one at a time, instead of implementing a global substitution like in the code, now export the form to a text file, replace it in a text file, and then return to the form.
Use 5:
Simplified conversion, Chinese and English conversion, generally on the control title, hint text, default values and so on text simplified conversion and can not really implement simplified conversion, open in the corresponding environment after the conversion will also appear ActiveX control cannot find or OLE error, the form or other objects converted to a text file before the simplified conversion, Then convert the corresponding character set, font name, section simplified corresponding name, CRC check code, and then back to access the corresponding object, you can complete the conversion of the entire Access program, the corresponding program effect can be see I do simplified conversion generic program, remember that the simplified is generally 134 traditional is 136 You open it in English. I advise, if you want to do the same function, then you better not to do, with my will have, so that I get the money, I commission 20% to you, and so on after two years to accumulate to 100 yuan I send you again:)
Use 6:
The conversion between the UK and China, although a small amount of manual conversion, but has saved a lot of time, but how to use formal expressions to correctly distinguish which is the title, hint text, message box also requires some skills.
Use 7:
Change the default properties of a control
In addition to the default properties of our design state modification control, the use of modifying the contents of a text file also achieves the effect of modifying the default properties of a control, and when a form or report is exported to a text file, all forms, control items, and default control properties are reflected in the text file. You can do this by modifying the settings for the default properties in this text file.
What is the default property? For example, you download a program from abroad, why add controls to the form, the control font is always serif, and the new form control in the Simplified Chinese environment, the font is "Arial", the new form control in the traditional Chinese environment, the font is "new Fine Ming Body", because the default property of the control caused
Use 8:
To achieve the effect of creating a form template automatically, will do a good job with the basic functions of the export to a text file to save, to the time needed to use, directly imported back immediately may have a common function of the form, do not need to start from the beginning, and then do a bit of automation, do a rich form function code library, Allows the user to choose a variety of features, and then from the code base to select the desired code to create a text file in the form of text files, and then the text file automatically assembled a perfect form, no need to user programming, he just select the field, choose the form function, choose the style, Choose a template to achieve a variety of input forms, inquiry form, analysis form, report statistics and so on, writing programs become assembly procedures. When everyone has nothing to do, we will develop each special component. Note that copying features and code in a text file, in terms of automatic programming, is more resilient and malleable than copying controls and code in a form.
Use 9:
If there are pictures or OLE objects in the form or report, the exported text file will contain their binaries, use regular expressions or other methods to extract the content and restore it to the appropriate picture file. To save images of forms and reports to files (Access does not support directly saving pictures of image controls to a file)
Use 10:
To implement the conversion of Access forms and reports to VB programs, there are now some professional programs to provide this functionality, I think the basic idea is to export forms and reports to a file file, and then analyze the differences between it and the VB form files, and then modify the text file to adapt to the needs of VB form can be achieved, But I do not have enough time to do these:), of course, if you extrapolate, you may also make a tool, the implementation of VB to convert the form to the Access program, after all, VB resources and rich skills for access to have a great use of value
Usage:
Modify the font name font size or other properties used in the Access object at once, and you can change the font and other properties of the form's datasheet to.
Application:
View the GUID of the form and control and use it for the appropriate purpose
Application:
Modify forms and reports information about the printer, why the print settings of the form cannot be saved, why open the report always prompts the original default printer does not exist, whether to use the current printer and so on, the information is actually saved in the form and report, open the text file, everything is clear, Through this function can realize a lot of powerful functions, everyone play imagination.
Usage:
If you want to get the properties of the form and the control, you can know a lot of things through a text file
Application:
Creating some new controls, such as combo boxes, list boxes, and so on, can be copied directly inside the code to create, and more useful is, some with registration information (license) of the control, if the original form is available, but you do not license, you copy the form will appear error, said you do not have copyright, But if you export the form to a text file and then back to a new form, Access will give you a pass, however, this method can not say I taught:), although I tried many times to try out, but I am determined not to use:), we all know, I generally in public, are used genuine:

Use 16:

You can use the above method to export all objects throughout access to a file for backup save, and then restore whichever you want to restore, although this method has its advantages, but the whole MDB backup may be more practical:)

Use 17:

Can be used for version control, I do not know whether you have used SourceSafe in Access, I studied for a short time, I found that its check-in check-out is using the method I said above, in SourceSafe saved is the text format of each object. If you are interested, can write a similar version control tool, I expect 2008 will start to write it, if you have written it before that year, it is best to send the source code to me, or I accuse you to steal my idea:)


Use 18:
In addition to forms and reports, there are almost a lot of other objects, such as queries, views, stored procedures, relationships, macros, modules and so on can be exported, you can use for a variety of purposes, here is not detailed, if you have a unique discovery, please tell me OH

Tmtony (Wang Yuhong)
Article Source: Access China/office China (www.office-cn.net)

Note, however, that the table is not exportable:)


In addition, we have to tell you that at the beginning of the 2002 (XP) version, Microsoft began to check the CRC checksum, so there may be some problems when returning objects. Maybe Microsoft already knows someone is abusing this feature:)

Haste and, the statement is not through or typo, also please leave a horse:)


This article is from the Office China Webmaster Blog, so be sure to keep this source http://tmtony.blog.51cto.com/8848389/1410540

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.