Solved

Table Column to Form- VBA

Posted on 2014-04-22
5
637 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 33

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 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 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 33

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now