[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Is there a way to get the code for the form created in Access?

I know that in Excel, you can "export" the form and in VB you can save the form and get the code on how to build that form.
I have not been able to find similiar in Access.
I am looking for coding on how to rebuild the look of the screen like where txtbox1 is, the size etc...
In Excel, I have been able to do this which allows me to write code to dynamically change the screens easily.
Thinks like adding rows as needed, change field size, I had before used several "templates" that allow me to change groups of items at once. I is really nice having the code layout so you know where to put things... The learning curve of moving from one product to another...
Or is there a tool that would allow me to get this?

Thanks!

Bruce
0
Bruj
Asked:
Bruj
1 Solution
 
Patrick MatthewsCommented:
As far as I know you cannot export access forms in quiyte the same way as in excel or word.

However, you can save your forms to another db, and then use TransferDatabase to import forms into your current database on demand.
0
 
Rey Obrero (Capricorn1)Commented:
not really sure what you are after, give this a try

fpath="C:\folderName\"
application.saveastext acForm, "form1", fPath &  "form1.txt"

open the text file form1.txt


to retrieve the form from the text file

application.loadfromtext acForm, "form1", fPath &  "form1.txt"
0
 
hitsdoshi1Commented:
You're creating Access objects (forms, controls). Access provides the
ability to use VBA to write script that can be triggered by different
events on an object (eg. button press, form open.. etc). Generally there
won't be any script unless you write it (or it has been generated by a
wizard or something).

eg. to view the VBA script behind a form open the form in design view
and select View/Code from the menu. Or, open the form/control's property
sheet and scroll down to the list of events. If there is VBA script
behind an event the text "[Event Procedure]" will be displayed. To
access it simply click on that text and then press the build button that
appears to the right.

If you really want to see what happens 'behind the scenes' when you create a
form, you can use the undocumented 'SaveAsText' method to save the
definition of a form to a text file. For example ...

Press Ctrl+F11 then Ctrl+G and type the following line and press enter and take a look at Form1.txt

SaveAsText acForm, "Form1", "c:\form1.txt"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dqmqCommented:
In Access, we normally construct forms in the design view GUI.  But, with much more effort the same forms can be created entirely in code.  

I believe the question is this:  After constructing a form in design mode, is there a way to automatically generate the code for creating the identical form.  Sort of: is there a way to decompile a form into VBA code.  
0
 
BrujAuthor Commented:
After doing some research, it appears that you can get all of the info by stepping through the controls.
 
Private Sub CommandButton1_Click()

Dim cCont As Control



    For Each cCont In Me.Controls
Debug.Print TypeName(cCont)
        If TypeName(cCont) = "TextBox" Then

            a = cCont.Name
            b = cCont.Top
            C = cCont.Left
            
' etc...

        End If
        If TypeName(cCont) = "Image" Then

            a = cCont.Name
            b = cCont.Top
            C = cCont.Left
            D = cCont.Picture
            
            ' etc...

        End If

     Next cCont



End Sub

Open in new window

Now... can anybody point me to a source of controls and a list of their properties? I spent about 2 hours looking for this but could not find it. I am SURE it is out there!


Thanks!
0
 
Rey Obrero (Capricorn1)Commented:
did you even try the post at http:#a35750629 ?
0
 
BrujAuthor Commented:
capricorn1
Yes I did.

I have many forms to convert, so I was hoping to create a module that would go through each vba project and then pull the forms.

Using the method (and it is very viable) What I would need to do is save it down to the file, then re-read the file to extract the info needed. I am not real strong reading in text files. This is the main issue with this approach. There are several PLUSes to it as well!

Ideally, what I want to get to is a point where all of the controls are able to be extracted and then VBA code written similiar to

dim MyForm as new form
with MyForm
.Caption = "My New Form"
.popup = True
.Modal = True
.border style
.scrollbars=xxx
.etc
end with


with textbox1
.name = "whatever"
.Top = xxx
.Left = xxxx
.Width = xxxx
Height = xxxx
.font = "Arial"
end with

Not very hard to convert from the txtfile as it is laid out very similiar.
I can open and read the file, but I dont know how to do it in chunks, and with the images being embedded, I am not sure how that would effect being able to put the whole file into a string to parse from. Of course I can research this. I was just thinking it would be easier to go straight from the origianl object.

There are several reasons I am looking for this information
First is as I listed above, so I can change the form dynamically

Second, it would allow me to port the forms to/From Excel to or from Access (I know I will need to change measurements)
Some of our programs, managemnt wants to have both apps able to run.

I would like to be able to work with the txt form as well, becuase it would allow me to convert some forms that we have in VB to VBA a little easier than opening up the project and then recreate the form manually.

As far as the forms I am now trying to work with in Access, I have embedded the images and so there is a lot of "garbage" in the txt file.



Thanks!
0
 
BrujAuthor Commented:
capricorn1, It was late last week, and I was trying to get out of the office. Sorry for not responding, which I should have at that time.
I do value your input and suggestions!
Thanks
0
 
Rey Obrero (Capricorn1)Commented:
see this link

Reading Text Files
http://access.mvps.org/access/modules/mdl0057.htm
0
 
BrujAuthor Commented:
Thank you much. I will play with this.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now