Solved

Table Column to Form- VBA

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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.

828 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