MS ACCESS CREATE TABLE with a calculated field through VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johny6685
    New Member
    • Dec 2014
    • 66

    #1

    MS ACCESS CREATE TABLE with a calculated field through VBA

    Hi

    Is there a way to create table with a calculated type column through VBA.

    Currently I am using the below code But I am getting, Syntax error in field Expression.

    Code:
    db.Execute "CREATE TABLE tblFields(FieldName TEXT (55), " _
    & "FieldValue TEXT (55), STotal NUMBER, Goods NUMBER, Goods% " _
    & "CALCULATED ([Goods]/[STotal]) );"

    Any Help pls!!!
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3665

    #2
    johny,

    One general rule is that tables should not have a calculated field. So, there is no calculated data type. However, you should be able to create a field of the type required and simply insert the value you are calculate.

    PS, check the spacing carefully in your code.

    Hope this helps.

    Comment

    • jforbes
      Recognized Expert Top Contributor
      • Aug 2014
      • 1107

      #3
      Typically, calculated columns are taken care of by a Query.

      First create a Table to store all the values entered by the user (or other method of input) then create a Query for any of your calculations. You can attempt to use the Query as the basis for your Form as long as the Query doesn't get to complex.

      You might want to refer to the following if you plan on creating an editable Form based on a Query:

      List of reasons why a Microsoft Access query will yield non-editable results.

      Comment

      • johny6685
        New Member
        • Dec 2014
        • 66

        #4
        Thank You both. I am going with both of your input i.e. creating a calculation within query and append to the table

        Comment

        Working...