Link to home
Start Free TrialLog in
Avatar of TimHudspith
TimHudspith

asked on

How to create a form for each Access table using VBA

I want to loop all the tables in my database and create a separate datasheet-view form for each.
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

Why do you want/need to do this?

You can already view tables in datasheet view.

Are you going to do something with the forms created that can't be done already?
imnorie,

In some cases you may want to view the form as a Datasheet, but you need certain Events (On Open, Before Update, ...etc), ...or want certain properties set (Allow edits, Data Entry)
You could just create a form using the form wizard which will make it for you.
@conagraman

That is what my code does
while the code thing sounds cool  why would you want to create forms at runtime?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@conagraman

I think that is the approach used in the link in the first comment in this thread.  Have you read the comments and followed the links in this thread?

============
I think I agree with you and minhvc in your approaches.  A subform that displays a datasheet view of the selected table (from the parent form) would only require the creation of a single new form.

However, as boag2000 commented, a datasheet view does not facilitate the creation of event code.  We haven't heard from TimHudspith about this, so it is purely speculation at this point.

============
I just wrote an article, inspired by this question.  I'll post a link when it is published.
boag2000

But why create a form for each table?

When you view a form in datasheet view a lot of it's events  aren't available, even if you've created them.

If you really want to view data in 'datasheet view' and still have all the events, properties of a form availbale why not create your own.

That's pretty straightforward to do using a continuous form.

You can even add buttons and other controls to each record of your 'datasheet', useful for navigation.
@ aikimark: i have read the comments now and i went to the link from minhvc: in 36259886 however it doesn’t show you the code to change the source object  which is for example
Me.datasheetfoerm.SourceObject = "table.table1"
the part worth noting is the "table." part if you didnt know that you might bang your head against the wall for a min. lol  the post also discourages the use of the technique because ..."can not set the properties of allowadditions, allowedits, etc"...  which is just not true.  although you would have to go about it a different ways it is possible to let or not let changes to occur in a datasheet view

Also your code aikimark looks like it might have a similar result as the code in the first post of the link from  minhvc except it doesn’t make datasheets instead it creates forms and adds controls. which would allow the use of event code. so perhaps if the author needs the ability of using events the post in the link might be a better way to go.
@ aikimark i think an article on the subject would be good. i had thought about it myself and i would like to read what you come up with. i think it would be worth mentioning in the article the ways to change the appearance of the datasheet in the control panel. Also any code that you are able to interact with the datasheet with such as the freeze panes.   Also the use of query defs for the control source perhaps just sugestions for it. I think I will let you run with it.
The uploaded database file has one form that illustrates the technique of using a child to display the selected table in a data sheet.  You will need to import this form into your database, since the uploaded database contains no tables.

 TableViewer.mdb
@TimHudspith

So your actual problem/need was to be able to see selected tables in a datasheet view?