Solved

Table Column to Form- VBA

Posted on 2014-04-22
5
665 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 34

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 34

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
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…

751 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