Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Table Column to Form- VBA

Posted on 2014-04-22
5
Medium Priority
?
693 Views
Last Modified: 2014-04-23
Hello

There is a table with 4 columns (lets say)
When i made a form initially, the table had 3 columns. so the form had 3 fields. Now how do i use vba to add the 4th new column to the form?

Thank you
0
Comment
Question by:Rayne
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Norie
ID: 40016719
How are you displaying the table on the form?
0
 

Author Comment

by:Rayne
ID: 40016979
Hello Imnorie,
The form has to be in datasheet view always
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 40017119
So you have a New column in the table, and now you want to add it on the form at runtime?

FWIW, this is a bad idea. Doing so decompiles the application, and can leave you in an unstable environment. Generally speaking, by the time you have created a Form the design of the database should be stabilized, and you should only be adding new columns and controls rarely (and you should be doing this in design view and then deploying a new FE to your users).

That said, in order to do this you'd have to add a new Textbox (or combo, or Checkbox, etc) control to the form in Design view, and then save the form.

Note you cannot do this if you're using the Runtime, since Access does not allow design changes.

DoCmd.OpenForm "YourForm", acDesign
CreateControl "YourForm", acTextBox, acDetail, , "YourColumn"
Docmd.Close acForm, "YourForm", acSaveYes

Note there are several other optional arguments for CreateControl, most of which have to do with positioning. With a Datasheet, that's not really important, since Access determines the layout.
0
 
LVL 35

Expert Comment

by:Norie
ID: 40017131
Open the form in design view, open the Field List and add the new field to the form.

Oops, think that's already been suggested.
0
 

Author Comment

by:Rayne
ID: 40017298
Hello Scott,

Yes totally agree, creating it in runtime is not logical. But I would want to have a button that i could press sometimes that does the form refresh and I think this serves that purpose

Thank you :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question