Solved

Table Column to Form- VBA

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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 …

740 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