Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Create from from table

Create from from table

Create from from table

In MS Access 2013 a form can automatically be created by clicking on a table name and then using the Create ribbon and Form button to automatically create a form. This is a very basic form but servers its purpose well for my project. Formatting is not an issue.

Now the question. I use code to import spreadsheet data to MS Access. This import will create a new table. The created table takes the name of the Excel Tab name. So, the code knows the table name. I want to add code to automatically create a form based on that table. Just like if I did it manually by selecting the table name and using the create ribbon Form button as described above.

Does anyone have any idea on how to do this with VBA?

RE: Create from from table

Try this:

function CreateForm (strTblName as string, intFormView as integer)

DoCmd.SelectObject acTable, strTblName, True

Select Case intFormView
Case 0: DoCmd.RunCommand acCmdNewObjectAutoForm
Case 1: DoCmd.RunCommand acCmdNewObjectContinuousForm
Case 2: DoCmd.RunCommand acCmdNewObjectDatasheetForm
Case 3: DoCmd.RunCommand acCmdNewObjectPivotTable
Case 4: DoCmd.RunCommand acCmdNewObjectPivotChart
Case 5: DoCmd.RunCommand acCmdNewObjectSplitForm
End Select
End Function

RE: Create from from table

Sorry it has taken so long to get back to you guys. When I first posted this I did it on 2 forums (Forms and VB). After several days without a response I posted on a third (Other). I got my first answer there and it was DoCmd.RunCommand acCmdNewObjectAutoForm. I want to thank you both for your responses. I will capture them for future use. Again, sorry about my tardiness.

RE: Create from from table

I do have a couple question for FancyPrairie.

1. I like your list of Form commands but I can't find the listing anywhere. Do you have a reference you could suggest?

2. Also, is there a similar listing for DoCmd.RunCommand acCmdNewObjectAutoReport. The AutoReport is not working well for me. The problem seems to be it truncates my list of fields in my table. Some tables, I would use this with, contain up to 20 columns. And, probably, do to the field name lengths, they all do not show on the auto created report. At this time I do not control the field names..they are imported from excel spreadsheets that I do not control...yet.

Any advice?...and I promise to watch for replies more often. smile

RE: Create from from table

It's been so long ago that I created that routine that I don't remember where I got the information. However, if you type DoCmd.RunCommand and press space while in the function it should list them all.

As far as the report goes, the page is only so wide, so it will probably truncate items. You could, however, change the size of the columns. Check out this site: Link

RE: Create from from table

Great. I downloaded the info for reports. And, when I get a chance I will do the typing thing for both forms and reports.

Thanks again,

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close