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

Exporting an Access Form to a text file (vb file?) 1

Status
Not open for further replies.

GComyn

Programmer
Jul 24, 2001
177
US
I posted this question in another thread, but the subject would not have caught anyone's attention to this question, so I decided to create a new thread.

Now, has anyone thought about creating an add-in or something that would save a form (or all of them) to a text file. I'm talking about the properties, the controls and all their properties, and the code.

If anyone has any ideas... I'm thinking maybe to save the form to look like a vb form (vb6 is what I use)... then it could also have an import feature that would read the file and recreate the form in another database.

I'm thinking about this because I have some forms that I want to keep, but I don't need them in the database. I'll probably just create an "Archive" database that would house these forms, but I would like to look at 'exporting' the forms to a text file... maybe even having it so that you can import them into a vb project, and have them look like they did in Access.....

Any help, hints, or pointers to where they are already created (don't want to recreate the wheel if I don't have to) are appreciated!

PS. I had some trouble posting this at first, so I just copied the text into a text file, and saved it, then went looking for the form to vb export help... and found a locked MDE add-in for MSAccess97... Can't find anything for 2000 or greater....

GComyn
 
You can use the properties of the form and of each control to export to a text file. I am not a VB6 person, but I know that using VBA in Access you can read these properties and output them in text. I guess you know what the VB6 file structure should look like.
 
yes (Or I can get it), but I didn't want to have to reinvent the wheel... if someone else had already done it.... guess I'll just start it, and if someone else get's to it first, great... if not, it'll be done.. (maybe not well... but at least it will be done...)

GComyn
 
Let me know if you want any assistance on this - I like challenging little projects to work through in my spare time.
 
k... I'll probably be uploading any intermediary (and the final product) to utteraccess.com... I'll post here when I get something up... 'cause I need to keep looking here to see if anyone answers the question....

GComyn
 
GComyn,
This exists, I have seen it. Buuuuuttttt I can find the link...[curse]

If I do I will post it....

 
Hitechuser, if you're thinking about the hidden methods .saveastext/loadfromtext of the application object referenced amongst other in thread705-834817, then you'll find GComyn have alredy visited the thread, and probably found the methods not to be sufficient.

Roy-Vidar
 
maybe even having it so that you can import them into a vb project
WARNING: An access form is very different from an UserForm ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The Visual Source Safe application extracts every object in the database into individual text files. That would be a simple way to get started.[smile]

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Almost forgot, here's a the text from a very simple form exported to VSS:
Code:
Version =19
VersionRequired =19
Checksum =1439041765
Begin Form
    AllowFilters = NotDefault
    RecordSelectors = NotDefault
    MaxButton = NotDefault
    MinButton = NotDefault
    ControlBox = NotDefault
    AutoCenter = NotDefault
    NavigationButtons = NotDefault
    AllowDeletions = NotDefault
    CloseButton = NotDefault
    DividingLines = NotDefault
    AllowAdditions = NotDefault
    AllowEdits = NotDefault
    DefaultView =0
    AllowUpdating =2
    ScrollBars =0
    PictureAlignment =2
    DatasheetGridlinesBehavior =3
    GridX =24
    GridY =24
    Width =4740
    DatasheetFontHeight =10
    ItemSuffix =12
    Left =2370
    Top =1455
    Right =6255
    Bottom =2520
    HelpContextId =-50012
    DatasheetGridlinesColor =12632256
    ShortcutMenuBar ="Main Popup"
    RecSrcDt = Begin
        0x8fd387773117e240
    End
    GUID = Begin
        0x58b6e6cd7c5f50429788088e5f7ac2d2
    End
    NameMap = Begin
        0x0acc0e55
    End
    Caption ="ClientInfosubform"
    OnOpen ="[Event Procedure]"
    HelpFile ="Main.hlp"
    DatasheetFontName ="Arial"
    Begin
        Begin Label
            BackStyle =0
            BackColor =-2147483633
            ForeColor =-2147483630
        End
        Begin Rectangle
            SpecialEffect =3
            BackStyle =0
        End
        Begin Line
            SpecialEffect =3
        End
        Begin Image
            BackStyle =0
            OldBorderStyle =0
            PictureAlignment =2
        End
        Begin CommandButton
            FontSize =8
            FontWeight =400
            FontName ="MS Sans Serif"
        End
        Begin OptionButton
            SpecialEffect =2
            LabelX =230
            LabelY =-30
        End
        Begin CheckBox
            SpecialEffect =2
            LabelX =230
            LabelY =-30
        End
        Begin OptionGroup
            SpecialEffect =3
        End
        Begin BoundObjectFrame
            SpecialEffect =2
            OldBorderStyle =0
            BackStyle =0
        End
        Begin TextBox
            SpecialEffect =2
            BackColor =-2147483643
            ForeColor =-2147483640
        End
        Begin ListBox
            SpecialEffect =2
            BackColor =-2147483643
            ForeColor =-2147483640
        End
        Begin ComboBox
            SpecialEffect =2
            BackColor =-2147483643
            ForeColor =-2147483640
        End
        Begin Subform
            SpecialEffect =2
        End
        Begin UnboundObjectFrame
            SpecialEffect =2
            OldBorderStyle =1
        End
        Begin ToggleButton
            FontSize =8
            FontWeight =400
            FontName ="MS Sans Serif"
        End
        Begin Tab
            BackStyle =0
        End
        Begin Section
            CanGrow = NotDefault
            Height =1260
            BackColor =-2147483646
            Name ="Detail"
            GUID = Begin
                0xf9cb8a6806c6e146a8c7c4a56e0f5adb
            End
            Begin
                Begin Label
                    OverlapFlags =93
                    Left =120
                    Top =120
                    Width =4440
                    Height =420
                    FontSize =14
                    FontWeight =700
                    ForeColor =-2147483639
                    Name ="lblCompanyName"
                    Caption ="Any Company, Inc"
                    FontName ="Arial"
                    GUID = Begin
                        0x081c96ee229e024a81fb46aae56a3410
                    End
                End
                Begin Label
                    OverlapFlags =95
                    Left =120
                    Top =540
                    Width =4440
                    Height =300
                    FontSize =12
                    FontWeight =700
                    ForeColor =-2147483639
                    Name ="lblAddress1"
                    Caption ="2002 Yellow Rose"
                    FontName ="Arial"
                    GUID = Begin
                        0xed720a97e5fa0e49928ad0d6bf5cdbc6
                    End
                End
                Begin Label
                    OverlapFlags =87
                    Left =120
                    Top =840
                    Width =4440
                    Height =300
                    FontSize =12
                    FontWeight =700
                    ForeColor =-2147483639
                    Name ="lblCityStateZip"
                    Caption ="Heart of, TX"
                    FontName ="Arial"
                    GUID = Begin
                        0x710f9cf6f70bb549bb305f3fd469f810
                    End
                End
            End
        End
    End
End
CodeBehindForm
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database

' info is cached at startup so the external call shouldn't run - mds
Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler
  If Not gbLoaded Then
      ' Load the data into the variables
      Call CacheCompanyInfo
  End If
  Me.lblCompanyName.Caption = gsCompanyName
  Me.lblAddress1.Caption = gsCompanyAddress1
  Me.lblCityStateZip.Caption = gsCompanyCityStateZip
ExitHere:
  Exit Sub
ErrHandler:
  Call LogError("Form: " & Me.Name, "Form_Open( )", Err, Err.Description)
  Resume ExitHere
End Sub

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Hey Roy,

Actually I remember seeing some sample MDB that proposes to do just that. It was not a link here..

Unfortunatly I can not find the site or link ... Then again I may not complety understand the request..

But hey.. I'l see what I can find...

Thanks..

 
I found the un-documented hidden method that VSS uses to export the objects through VBA. It's very simple and doesn't require any references to call:
Code:
Application.SaveAsText acForm, "Customers", "C:\custExported.txt"

To load a form back in to access from a text file:
Code:
Application.LoadFromText acForm, "Customers", "C:\custExported.txt"

One note: When you call LoadFromText to import an object, if an object with the same name already exists, it will be overwritten without warning. Therefore it would be necessary to check for the existence of the object before allowing the import.

If you examine the text format of the exported files, it is almost identical to a VB5 or VB6 form file (.frm) and only some control naming changes would probably have to be made.

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Here's a minimal VB5 .frm file (no code):
Code:
VERSION 5.00
Begin VB.Form Dialog 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Dialog Caption"
   ClientHeight    =   3195
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   6030
   Height          =   3600
   Left            =   2700
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   6030
   ShowInTaskbar   =   0   'False
   Top             =   3405
   Width           =   6150
   Begin VB.CommandButton CancelButton 
      Caption         =   "Cancel"
      Height          =   375
      Left            =   4680
      TabIndex        =   1
      Top             =   600
      Width           =   1215
   End
   Begin VB.CommandButton OKButton 
      Caption         =   "OK"
      Height          =   375
      Left            =   4680
      TabIndex        =   0
      Top             =   120
      Width           =   1215
   End
End
Attribute VB_Name = "Dialog"
Attribute VB_Base = "0{A64D0C93-7CF4-11CF-AD88-00AA00614F3E}"
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Attribute VB_Customizable = False

Option Explicit

The Access forms have many more attributes than VB forms, mostly due to the data-binding capabilities. Still, it's in the ballpark. [rainbow]

VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
VBSlammer,

THANKS Dude!! that's exactly what I was looking for... the VB import was secondary... but I wanted to be able to take the forms out of a database and keep them in text files, which are much less volatile.

If, as an addition, I can use the text files in a vb program, that would be an additional plus!

Thanks... you got a star from me!

Ok... I've tested the above .SaveAsText, and it seems to be able to export/import everything except tables... I keep getting error 2487 "The Object Type argument for the action or method is blank or invalid"... which is fine, I just have to write or find a custom function that will export/import tables formats, as well as data... not necessarily in the same file.

Thanks Again!!!

GComyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top