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

Create from from table 1

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
0
0
US
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?
 
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
 
I suggested something similar but without the nice wrapper function but Puforee hasn't replied. thread181-1776908

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
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.
 
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. :)
 
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
 
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,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top